nnhubbard / ZSSRichTextEditor

A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view
MIT License
3.78k stars 585 forks source link

ZSSToolbarInsertImageFromDevice Custom Order Crash #132

Closed ghost closed 8 years ago

ghost commented 8 years ago

When using a custom order with a select few bar button items, if I include ZSSToolbarInsertImageFromDevice I get a crash on:

self.toolbar.items = items; (line 715 in buildToolBar method)

Error:

*\ Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString view]: unrecognized selector sent to instance 0x100228460'

purplepeng commented 8 years ago

@william205 I have the same problem,what's your solution?Thanks.

ghost commented 8 years ago

I managed to fix it by changing a line of code in the ZSSRichTextEditor.m source file.

Try going to the following method:

- (NSArray *)itemsForToolbar

Then find

// Image From Device
if ((_enabledToolbarItems && [_enabledToolbarItems containsObject:ZSSRichTextEditorToolbarInsertImageFromDevice]) || (_enabledToolbarItems && [_enabledToolbarItems containsObject:ZSSRichTextEditorToolbarAll])) {
    ZSSBarButtonItem *insertImageFromDevice = [[ZSSBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ZSSimageDevice.png"] style:UIBarButtonItemStylePlain target:self action:@selector(insertImageFromDevice)];
    insertImageFromDevice.label = @"imageFromDevice";
    if (customOrder) {
        [items replaceObjectAtIndex:[_enabledToolbarItems indexOfObject:ZSSRichTextEditorToolbarInsertImage] withObject:insertImageFromDevice];
    } else {
        [items addObject:insertImageFromDevice];
    }
}

I changed the following line:

[items replaceObjectAtIndex:[_enabledToolbarItems indexOfObject:ZSSRichTextEditorToolbarInsertImage] withObject:insertImageFromDevice];

to:

[items replaceObjectAtIndex:[_enabledToolbarItems indexOfObject:ZSSRichTextEditorToolbarInsertImageFromDevice] withObject:insertImageFromDevice];

After I did that it all worked perfectly.

nnhubbard commented 8 years ago

Can you submit a PR for this?

ghost commented 8 years ago

Pull request submitted

nnhubbard commented 8 years ago

Merged. Thanks!

ghost commented 8 years ago

No problem

purplepeng commented 8 years ago

Thanks. There also have a small problem. The ZSSimageDevice.png image was not placed in the same path with others. sourceimage

ghost commented 8 years ago

I will submit a pull request for that to.