我有一种情况,必须在我的UITableView
中插入单元格。 我实现了这三个代表功能,当数据在viewDidLoad
中定义时,它运行良好。无法在UITableView中插入单元格来自API的数据
- (void)viewDidLoad {
[super viewDidLoad];
categoryData = [NSMutableArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee",@"Ham and Cheese Panini", nil];
_categoryMenuTable.dataSource = self;
_categoryMenuTable.delegate = self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [categoryData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:[categoryData objectAtIndex:indexPath.row]];
return cell;
}
但在我的情况下categoryData
来自一个API异步,viewDidLoad
后明显加载。
所以真正的问题是,在后面的情况下,我无法调用委托方法。
PS我也试过
[_categoryMenuTable reloadData];
像
-(void)setCategories:(NSMutableArray*)arr {
categoryData = arr;
_categoryMenuTable.dataSource = self;
_categoryMenuTable.delegate = self;
[_categoryMenuTable reloadData];
}
数据设置为categoryData
后,我还有一点我想提的是,我使用MMDawerController https://github.com/mutualmobile/MMDrawerController
我怎样才能得到从API的数据到我的表?
如何解析来自服务器的数据? – shpasta
我解析它并将其存储在一个NSMutableArray * arr –
你可以展示你是如何做这件事的,即数据解析。 – shpasta