0
不同部分的細胞,因爲我想在不同部分的行點擊時傳遞不同的頁面傳遞不同的頁面。如何通過選擇的tableView在IOS
@interface TableView()<UITableViewDelegate, UITableViewDataSource>
{
NSArray *tableData;
NSArray *imagesArray;
}
@end
@implementation TableView
- (void)viewDidLoad {
[super viewDidLoad];
tableData=[NSArray alloc];
[email protected][@"Delhi",@"NewYork",@"London",@"Paris",@"Munich",@"Germany",@"Delhi",@"NewYork",@"London",@"Paris",@"Munich",@"Germany",@"Delhi",@"NewYork",@"London",@"Paris",@"Munich",@"Germany"];
imagesArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"delhi.jpg"],
[UIImage imageNamed:@"newyork.jpg"],
[UIImage imageNamed:@"london.jpg"],
[UIImage imageNamed:@"paris.jpg"],
[UIImage imageNamed:@"munich.jpg"],
[UIImage imageNamed:@"germany.jpg"],
[UIImage imageNamed:@"delhi.jpg"],
[UIImage imageNamed:@"newyork.jpg"],
[UIImage imageNamed:@"london.jpg"],
[UIImage imageNamed:@"paris.jpg"],
[UIImage imageNamed:@"munich.jpg"],
[UIImage imageNamed:@"germany.jpg"],
[UIImage imageNamed:@"delhi.jpg"],
[UIImage imageNamed:@"newyork.jpg"],
[UIImage imageNamed:@"london.jpg"],
[UIImage imageNamed:@"paris.jpg"],
[UIImage imageNamed:@"munich.jpg"],
[UIImage imageNamed:@"germany.jpg"],
nil];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section==0)
{
return 1;
}
else if(section==1)
{
return 1;
}
else
{
return 1;
}
//return [tableData count]/2;
return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"SimpleTableItems";
NSString *str;
UIImage *image;
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:stringt ];
if(cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:stringt];
}
else if (indexPath.section==0)
{
str=[tableData objectAtIndex:indexPath.row];
//cell.textLabel.text=[tableData objectAtIndex:indexPath.row];
//cell.imageView.image = [imagesArray objectAtIndex:indexPath.row];
image=[imagesArray objectAtIndex:indexPath.row];
[cell.imageView setImage:image ];
[cell.textLabel setText:str];
// cell.imageView.image=[UIImage imageNamed:@"test.jpg"];
}
else if (indexPath.section==1)
{
str=[tableData objectAtIndex:indexPath.row];
image=[imagesArray objectAtIndex:indexPath.row];
//cell.imageView.image = [imagesArray objectAtIndex:indexPath.row];
[cell.imageView setImage:image ];
[cell.textLabel setText:str ];
}
else if (indexPath.section==2)
{
str=[tableData objectAtIndex:indexPath.row];
image=[imagesArray objectAtIndex:indexPath.row];
[cell.imageView setImage:image ];
[cell.textLabel setText:str];
}
//cell.imageView.image=[UIImage imageNamed:@"test.jpg"];
//[cell.textLabel setText:str];
return cell;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *header;
if(section==0)
{
[email protected]"Section 1 Header";
}
else if(section==1){
[email protected]"Section 2 Header";
}
else
{
[email protected]"3 header";
}
return header;
}
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
NSString *footer;
if(section==0)
{
[email protected]"Section 1 footer";
}
else if(section==1)
{
[email protected]"Section 2 Footer";
}
else
{
[email protected]"Section 3 Footer";
}
return footer;
}
#pragma mark - TableView delegate
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES ];
UITableViewCell *tableCell=[tableView cellForRowAtIndexPath:indexPath];
NSLog(@"Section %d rows %d selected and it's data is %@",indexPath.section,indexPath.row,tableCell.textLabel.text);
}
首先在第2和第3條的tableView細胞沒有顯示,但是當我點擊該行已選定這一點,指定它只能創造空間。
對行選擇什麼ü想要做@narendrapandey –
對行選擇的價值,我想創建另一個視圖。 –
只有第1部分我得到的圖像和數據不是在所有部分。請指定錯誤 –