UILabel テキスト プロパティを設定しようとしましたが、例外 NSInvalidArgumentException reason: '-[NSNull length]: unrecognized selector sent to instance 0x2591068 が発生しました
デバッグを行った後、設定しようとしている値が であることがわかりますが、これが問題である理由がわかりません。データベースの結果とオブジェクトで NULL が返される方法に関連しているようです。これが背景です。
////////
ContactsModel - これは、データベースの NSArray からの結果が取り込まれた私のオブジェクトです。
#import "ContactModel.h"
@implementation ContactModel
@synthesize contactId;
@synthesize status;
@synthesize phone1;
@synthesize thumb_url;
@synthesize fullname;
@synthesize phone2;
- (id)init {
self = [super init];
if (self) {
self.thumb_url = nil;
self.status = nil;
self.fullname = nil;
self.phone1 = nil;
self.phone2 = nil;
}
return self;
}
///////View Controller
リスト ビュー。- リスト ビューは、以下のセグエを介して、入力されたオブジェクトを詳細ビューに渡します。
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"pushContactDetail"])
{
GlobalVars * sharedGlobalVars = [GlobalVars sharedGlobalVars];
NSArray *indexPaths = [self.imageCollection indexPathsForSelectedItems];
ContactDetail *detailView = (ContactDetail *) segue.destinationViewController;
NSIndexPath *index = [indexPaths objectAtIndex:0];
NSLog(@"%d", index.section * 2 + index.row);
//TODO: Figure out what the hell this means
ContactModel *contact =[sharedGlobalVars.contactsContent objectAtIndex:index.section * 2 + index.row];
detailView.contact = contact;
}
詳細ビュー- このメソッドでオブジェクトを UI に割り当てます
- (void) loadContent
{
ImageCache *imgCache = [ImageCache sharedImageCache];
//publisherPhone1.text = self.contact.phone1;
publisherPhone2.text = self.contact.phone2; //THIS NOT WORKING IF NULL
publisherFullName.text = self.contact.fullname;
UIImage *image = [imgCache getCachedImage:self.contact.thumb_url];
publisherImage.image = image;
}
ここにオブジェクトの値を出力すると、得られるものの例です
The value of phone2: <null>
テスト目的で load content メソッドを変更して self.contact.phone2 = nil に設定すると、すべて問題ありません。これが、 と nil の間に違いと問題があると私が考えるように導いているものです。
あなたが提供できる助けをありがとう