私はテーブルビューをnsarrayでバインドしようとしていますが、Webサービスからデータを取得してnsArrayに入れました.nsarrayは正常に埋められましたが、テーブルビューのセルにバインドできません。
テーブルビューをNSArrayのコンテンツにバインドできませんか?
私は私の細胞
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"ContactCell";
ContactTableViewCell *cell = (ContactTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[ContactTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
Contact * contact = _contacts[indexPath.row];
RAC(cell.fullNameLabel , text) = RACObserve(contact,firstName);
RAC(cell.phoneNumberLabel , text) = RACObserve(contact,phoneNumber);
UIImage *contactImage = [UIImage imageNamed:@"contactPicture.png"];
[cell.contactImage setImage:contactImage];
return cell;
}
を作成し、それは私が選択したセルの内容をチェックするためのメソッドを追加しました私はNSArrayの
#import <UIKit/UIKit.h>
#import <ReactiveCocoa/ReactiveCocoa.h>
@interface ContactsTableView : UITableView <UITableViewDataSource,UITableViewDelegate>
@property (strong,nonatomic) NSMutableArray * contacts;
- (instancetype) init;
@end
を持っている私の.hファイルだ彼女、同じインデックスのパスにあるnsarrayは次のようになります。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
ContactTableViewCell *selectedCell=[tableView cellForRowAtIndexPath:indexPath];
[selectedCell.contentView addSubview:selectedCell.fullNameLabel];
NSLog(@"phoneLabel of cell %@", selectedCell.phoneNumberLabel.text);
NSLog(@"phone number of array %@", ((Contact *) _contacts[indexPath.row]).phoneNumber);
}
これはoutp UT:
crm-app[49692:1409964] **phoneLabel of cell (null)**
2017-05-15 12:25:56.941 crm-app[49692:1409964] **phone number of array 0655443345**
ここにブレークポイントを追加する* contact = _contacts [indexPath.row];連絡先に値が入っているかどうか確認してください –
IBOutletが接続されていないようですが、再度確認してください! –