我有任何數量的單個數組。我想在不同的部分劃分爲7的倍數。我無法得到這個工作。這是一個2個元素的例子。如何在節中操作數組?
- (void)viewDidLoad {
[super viewDidLoad];
array =[NSMutableArray arrayWithObjects:@"d",@"s",@"a",@"qq",@"dqd",@"dqq",@"qdqdf",@"dqdfqf", nil];
// Do any additional setup after loading the view from its nib.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ceil(array.count/2.0); // round up the floating point division
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger sections = [self numberOfSectionsInTableView:tableView];
if (section == sections - 1) {
NSInteger count = array.count & 2;
if (count == 0) {
count = 2;
}
return count;
} else {
return 2;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
// cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
@rmaddy請幫助這項工作 –
發佈答案後不要完全改變你的問題。它使答案毫無價值。 – rmaddy