-1
私は1つの配列(arrData)とUITableViewCell reload arrDataを持っています。 arrDataオブジェクトのWebサービス配列に格納されます。 UITableViewCellは2つのラベルにあり、1つのイメージ、ラベルおよびイメージはarrDataによってデータをロードします。すべてのラベルとイメージは同じ配列にリロードされますが、私は別の異なる配列を各ラベルとイメージに再ロードします。他の配列に格納されたUITableViewCell
のViewController
#import "ViewController.h"
#import "MemberTableViewCell.h"
#import "member_details.h"
@interface ViewController()
{
NSArray *arrData;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.tabel_view setAllowsMultipleSelection:YES];
NSURLRequest *req=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://edutimeapp.com/toshow/chamber-of-commerc/ws/fetch_member.php"]];
response =[[NSMutableData alloc]init];
[NSURLConnection connectionWithRequest:req delegate:self];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[response appendData:data];
NSLog(@"error receving data %@",response);
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(@"Error in receiving data %@",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"response data %@",json);
NSArray *status = json[@"status"];
arrData = status;
[self.tabel_view reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray<NSIndexPath *> *selectedRows = [tableView indexPathsForSelectedRows];
if (selectedRows && [selectedRows containsObject:indexPath]) {
return 127.0; // Expanded height
}
return 50.0; // Normal height
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arrData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MemberTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ht"];
if (cell==nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.name.text= [[arrData objectAtIndex:indexPath.row] valueForKey:@"business_category_name"];
cell.title.text= [[[[arrData objectAtIndex:indexPath.row] valueForKey:@"business_details"] objectAtIndex:0] valueForKey:@"name"];
cell.email.text=[[[[arrData objectAtIndex:indexPath.row] valueForKey:@"business_details"] objectAtIndex:0] valueForKey:@"email"];
cell.image_view.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[[[[arrData objectAtIndex:indexPath.row]valueForKey:@"business_details"]objectAtIndex:0] valueForKey:@"img_url"]]]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self updateTableView];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self updateTableView];
}
- (void)updateTableView
{
[self.tabel_view beginUpdates];
[self.tabel_view endUpdates];
}
@end
このコードを試してみてください。また、xibでプロトタイプのセルまたはカスタムセルを使用していることをお知らせください。 –
@BharatModiストーリーボードのカスタムセルと私は私の質問を編集します。 –
@BharatModi再度質問を更新します。 thnx –