Tôi có NSMutableArray với dữ liệu (mã hóa cứng).Làm cách nào để sử dụng NSMutableArray làm Nguồn dữ liệu cho UITableView
tôi thực hiện hai phương pháp TableView và IB, tôi đã thiết lập các đại biểu và nguồn dữ liệu
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"] autorelease];
}
cell.textLabel.text = [myArray objectAtIndex:[indexPath row]];
NSLog(@"Cell is %@", [myArray objectAtIndex:indexPath.row]);
return cell;
}
Các dữ liệu sẽ không xuất hiện trong TableView. Tôi đã chạy NSLog và tôi có thể thấy dữ liệu nằm trong myArray.
Tôi đã thêm NSLog vào mã và dường như mã không bao giờ thực hiện. Câu hỏi đặt ra là mảng của tôi được tạo ra như thế nào?
Dưới đây là đoạn code
- (id)init:(NSMutableArray *)theArray
{
[super init];
countryTable.delegate = self;
countryTable.dataSource = self;
UITapGestureRecognizer * tapRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)] autorelease];
[window addGestureRecognizer:tapRecognizer];
myArray = [[NSMutableArray alloc] init];
myArray = theArray;
return self;
}
cách bạn tạo 'NSMutableArray'? – WrightsCS