创建cell:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mycell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mycell1"];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60.0f;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row < [cities count] && !self.editing){
cityarray *city=[cities objectAtIndex:[indexPath row]];
citydescViewController *desc=[[citydescViewController alloc]init];
desc.name=city.cityname;
desc.desc=city.citydesc;
desc.img=city.cityimage;
[self.navigationController pushViewController:desc animated:YES];
}
if (indexPath.row == [cities count] && self.editing) {
AddcityViewController *addcity=[[AddcityViewController alloc]init];
addcity.cities=cities;
[self presentViewController:addcity animated:YES completion:nil];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
有效的单元格数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int count = (int)cities.count;
if (self.editing) {
count += 1;
}
return count;
}