【发布时间】:2015-09-13 02:26:58
【问题描述】:
这是当前屏幕:
如您所见,这是所提供服务的列表。我从公司的 api 中检索了数据,并且表格视图单元格是动态填充的。
这是它应该如何工作的:
单击其中一个单元格时,类似手风琴的效果应该会展开单元格并显示特定服务的更多详细信息。再次单击它或单击其他服务应将其关闭。我应该如何实现这个?
这是cellForRowAtIndexPath的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ServiceCell" forIndexPath:indexPath];
// Configure the cell...
Service * serviceObject;
serviceObject = [servicesArray objectAtIndex:indexPath.row];
//Configuring the images
Image * air = [[Image alloc] initWithLocation:@"icons/air.png" andWithServiceID:21];
Image * pest = [[Image alloc] initWithLocation:@"icons/pest.png" andWithServiceID:18];
Image * carpenter = [[Image alloc] initWithLocation:@"icons/carpenter" andWithServiceID:16];
Image * laundry = [[Image alloc] initWithLocation:@"icons/laundry" andWithServiceID:20];
Image * electrician = [[Image alloc] initWithLocation:@"icons/electrician.png" andWithServiceID:17];
Image * plumber = [[Image alloc] initWithLocation:@"icons/plumber.png" andWithServiceID:14];
Image * appliance = [[Image alloc] initWithLocation:@"icons/appliance.png" andWithServiceID:15];
NSArray * images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:air.location], [UIImage imageNamed:pest.location], [UIImage imageNamed:carpenter.location], [UIImage imageNamed:laundry.location], [UIImage imageNamed:electrician.location], [UIImage imageNamed:plumber.location], [UIImage imageNamed:appliance.location], nil];
if([serviceObject.serviceID isEqualToNumber:[[NSNumber alloc] initWithInt:air.serviceID]]){
cell.imageView.image = images[0];
}else if([serviceObject.serviceID isEqualToNumber:[[NSNumber alloc] initWithInt:pest.serviceID]]){
cell.imageView.image = images[1];
}else if([serviceObject.serviceID isEqualToNumber:[[NSNumber alloc] initWithInt:carpenter.serviceID]]){
cell.imageView.image = images[2];
}else if([serviceObject.serviceID isEqualToNumber:[[NSNumber alloc] initWithInt:laundry.serviceID]]){
cell.imageView.image = images[3];
}else if([serviceObject.serviceID isEqualToNumber:[[NSNumber alloc] initWithInt:electrician.serviceID]]){
cell.imageView.image = images[4];
}else if([serviceObject.serviceID isEqualToNumber:[[NSNumber alloc] initWithInt:plumber.serviceID]]){
cell.imageView.image = images[5];
}else{
cell.imageView.image = images[6];
}
//Setting the row labels
cell.textLabel.text = serviceObject.serviceName;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
我目前正在使用 Xcode 6.3.2 和最新的 iPhone SDK。
感谢任何帮助。谢谢。
【问题讨论】:
-
发布关于 cellForRowAtIndexPath 和 numberOfRowsInSection 和 didSelectRowAtIndexPath 的部分代码
-
看看下面我的回答——这就是你需要的
标签: ios iphone xcode uitableview cocoa-touch