-1
하나의 배열 (arrData) 및 UITableViewCell reload arrData 있습니다. arrData 객체의 웹 서비스 배열에 저장됩니다. UITableViewCell은 두 개의 레이블에 있고 하나의 이미지, 레이블 및 이미지는 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
귀하의 질문이 명확하지 않습니다이 코드를 시도 arrData에 포함 된 데이터를 제공한다. 또한 프로토 타입 셀 또는 xib와 함께 사용자 정의 셀을 사용하고 있다는 사실을 알려주십시오. –
@BharatModi 스토리 보드가있는 맞춤 셀과 내 질문을 수정합니다. –
@BharatModi 다시 질문을 올려주세요. thnx –