https://stackoverflow.com/a/11251478/3741799
인코딩에 복귀 NSObject 클래스에 이미지를 넣고 NSString을 넣습니다.
self.newData.imageString = [self encodeToBase64String: image];
다음의 TableView에서 새 개체를로드있는 tableView
- (Void) insertNewObject: (id) sender {
if (! self.objects) {
[self.objects addObject: self.newData.imageString];
[self.tableView reloadData];
}
[self.objects InsertObject: self.newData atIndex: 0];
NSIndexPath * indexPath = [NSIndexPath indexPathForRow: 0 inSection: 0];
[self.tableView insertRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationAutomatic];
}
을 새 개체를 추가!
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
static NSString * CellIdentifier = @ "Custom";
CustomCell * cell = (CustomCell *) [self.tableView dequeueReusableCellWithIdentifier: CellIdentifier forIndexPath: indexPath];
ObjectClass * object = [self.objects objectAtIndex: indexPath.row];
cell.imageView.image = [self decodeBase64ToImage: object.imageString];
return cell;
}
그러나 null 값을 가지고 있기 때문에 셀에서 이미지를로드 할 때 문자열을 디코딩 할 수 없으며 앱이 다운됩니다. 나는이 문제에 있다고 생각 - '전무 문자열 인수 [: 옵션 : _ NSPlaceholderData initWithBase64EncodedString :] * :'
인해 캐치되지 않는 예외 'NSInvalidArgumentException'응용 프로그램 종료, 이유는
* 인코딩하지만 나는 그것을 스스로 해결할 수 없다!
어디서 잘못 되었나요?
감사
이질문의 업데이트 Zaph 질문이 옳다
가, 내가 더 잘 설명하려고 : 내가 빈 테이블 뷰를 가지고, 사용자는 이미지와 각각의 텍스트 문자열을 추가합니다 열. 그래서 나는 속성 @property는 NSString * itemName에 추가 클래스 XYZToDoItem에서 애플
이 가이드의 공식을 사용하려고; 사용자가 만든 텍스트 문자열을 쉽게 추가 할 수 있습니다. 하지만이 클래스에 이미지를 추가하려면 어떻게해야합니까? 그래서 이미지를 문자열로 변환하고 @property NSString * imageString 속성을 추가한다고 생각했습니다. 하지만 잘못된 것이고 나는 그것을 할 수 없습니다! 더 좋은 방법을 제안 할 수 있습니까?
많은 도움과 협조에 감사드립니다.
self.objects
가nil
경우
왜 NSData를 Base64로 인코딩 된 NSString으로 변환하고 있습니까? 이 인코딩/디코딩으로 무엇을하려합니까? 'cellForRowAtIndexPath :'의 – zaph
은'self.objects'를 존재합니까? 귀하의'insertNewObject :'메소드에서 if (if self.objects가 nil'if (! self.objects) {'인지 검사하고 if가 있으면'addObject :'를 호출합니다. 먼저'self.objects'를 만들고 나서'addObject :'를 호출하고 싶습니다. –
Zaph에 감사드립니다. 질문을 업데이트했습니다 !! – Ragazzetto