我有一個自定義表格單元格類。難以置信,從類中檢索一個字符串
TextInput.h
@interface TextInput : UITableViewCell <UITextFieldDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate> {
UILabel *cellLabel;
UITextField *textFieldBox;
NSString *imageFile;
}
@property (nonatomic, retain) UITextField *textFieldBox;
@property (nonatomic, retain) UILabel *cellLabel;
@property (nonatomic, retain) NSString *imageFile;
它裏面有一個攝像頭按鈕,圖像保存到本地文件夾。我將文件名保存到imageFile中,該文件使用唯一的名稱生成。
Textinput.m
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
//retrieve image
UIImage *image = [info objectForKey: @"UIImagePickerControllerOriginalImage"];
imageFile = [self findUniqueSavePath];
[self saveImage:image:imageFile];
//dismiss the camera
CoreTableAppDelegate *mainDelegate = (CoreTableAppDelegate *) [[UIApplication sharedApplication] delegate];
[mainDelegate.rootViewController dismissModalViewControllerAnimated: YES];
}
- (NSString *)findUniqueSavePath {
NSString *path;
CFUUIDRef uuid = CFUUIDCreate(NULL);
NSString *uuidString = [(NSString *)CFUUIDCreateString(NULL, uuid) autorelease];
CFRelease(uuid);
path = [uuidString stringByAppendingPathExtension: @"png"];
return path;
}
一切正常,除非我想要從父的UITableView類的文件的名稱罰款。
EditTankDescription.m
- (void)getCell
{
TextInput *cell1 = (TextInput *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
NSLog(@"save imageFile:%@", cell1.imageFile); <***** crashes on this line
}
它崩潰與一個EXC_BAD_ACCESS的NSLog的聲明。這就像imageFile不是NNString。如果我設置imageFile = @「SOME隨機字符串」,沒有錯誤。 我很難過。
感謝您的任何見解。
不錯的想法,但cell1確實返回一個TextInput的uitableview單元格。如果我檢索一個隨機字符串,那很好。它只與imageFile崩潰。 – Mistergreen
我想我得出的結論是UITableViewCell類有一些奇怪的地方。它不喜歡非視圖類型的屬性。所以,如果我將我的文件名存儲到一個UIable中並像NSString myFile = cell1.cellLable.text那樣檢索它,那麼它工作正常。 – Mistergreen