2016-06-30 12 views
-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 
+1

このコードを試してみてください。また、xibでプロトタイプのセルまたはカスタムセルを使用していることをお知らせください。 –

+0

@BharatModiストーリーボードのカスタムセルと私は私の質問を編集します。 –

+0

@BharatModi再度質問を更新します。 thnx –

答えて

0

あなたの質問はarrDataに含まれるデータを提供し、明確ではありません

#import "ViewController.h" 
@interface ViewController() 
{ 
IBOutlet UITableView *tbl; 
NSMutableData *response; 
NSMutableArray *Arrdata; 
NSMutableArray *ArrySubData; 
} 
@end 
@implementation ViewController 
- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
Arrdata=[[NSMutableArray alloc]init]; 
ArrySubData=[[NSMutableArray alloc]init]; 
[tbl 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; 
NSLog(@"%@",Arrdata); 
[tbl reloadData]; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
ArrySubData=[[Arrdata objectAtIndex:section] objectForKey:@"business_details"]; 
return ArrySubData.count; 
} 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
return [NSString stringWithFormat:@" %@",[[Arrdata objectAtIndex:section] objectForKey:@"business_category_name"]]; 
} 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
return 25; 
} 
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 

UILabel *myLabel = [[UILabel alloc] init]; 
myLabel.frame = CGRectMake(0, 0, 320, 20); 
myLabel.font = [UIFont fontWithName:@"Roboto-Bold" size:13.0]; 
myLabel.textColor=[UIColor whiteColor]; 
myLabel.backgroundColor=[UIColor colorWithRed:70.0/255.0 green:82.0/255.0 blue:88.0/255.0 alpha:1.0]; 
myLabel.text = [self tableView:tableView titleForHeaderInSection:section]; 
UIView *headerView = [[UIView alloc] init]; 
[headerView addSubview:myLabel]; 
return headerView; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
if (cell == nil){ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 
UIImageView *ImgBrands = (UIImageView *) [cell viewWithTag:101]; 
UILabel *lblName = (UILabel *) [cell viewWithTag:102]; 
UILabel *lblEmail = (UILabel *) [cell viewWithTag:103]; 
UILabel *lblPhone = (UILabel *) [cell viewWithTag:104]; 

ArrySubData=[[Arrdata objectAtIndex:indexPath.section] objectForKey:@"business_details"]; 
NSString *strName=[NSString stringWithFormat:@"%@",[[ArrySubData objectAtIndex:indexPath.row] objectForKey:@"name"]]; 
NSString *stremail=[NSString stringWithFormat:@"%@",[[ArrySubData objectAtIndex:indexPath.row] objectForKey:@"email"]]; 
NSString *strphone=[NSString stringWithFormat:@"%@",[[ArrySubData objectAtIndex:indexPath.row] objectForKey:@"phone"]]; 
NSString *strimage=[NSString stringWithFormat:@"%@",[[ArrySubData objectAtIndex:indexPath.row] objectForKey:@"image"]]; 

lblName.text=strName; 
lblEmail.text=stremail; 
lblPhone.text=strphone; 
ImgBrands.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strimage]]]; 
return cell; 

} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
[self updateTableView]; 
} 
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
[self updateTableView]; 
} 
- (void)updateTableView 
{ 
[tbl beginUpdates]; 
[tbl endUpdates]; 
} 
+0

セクション内にbusiness_category_nameを表示し、モバイル、メール、画像をセルに表示することができます –

関連する問題