I've created a tableView with only 1 section and it keep returning 0 in all indexPath.Row. What am I doing wrong? here is me logging the indexPath
<NSIndexPath: 0xd2897d0> {length = 2, path = 0 - 0}
<NSIndexPath: 0xd290af0> {length = 2, path = 1 - 0}
<NSIndexPath: 0xd2a5cd0> {length = 2, path = 2 - 0}
<NSIndexPath: 0xd2a8340> {length = 2, path = 3 - 0}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
if (indexPath.row < 3) {
TextFieldTableViewCell *accountCell = [tableView dequeueReusableCellWithIdentifier: textFieldCellIdentifier forIndexPath: indexPath];
accountCell.cellTextField.delegate = self;
accountCell.cellLabel.text = [accountArray objectAtIndex: indexPath.row];
if (indexPath.row == 0) {
accountCell.cellTextField.keyboardType = UIKeyboardTypeDefault;
} else if (indexPath.row == 1) {
accountCell.cellTextField.keyboardType = UIKeyboardTypeNumberPad;
} else if (indexPath.row == 2) {
accountCell.cellTextField.keyboardType = UIKeyboardTypeNumberPad;
}
cell = accountCell;
} else if (indexPath.row == 3) {
ACEExpandableTextCell *textViewCell = [tableView expandableTextCellWithId:@"cellId"];
textViewCell.text = [self.cellData objectAtIndex:indexPath.section];
textViewCell.textView.placeholder = @"Placeholder";
cell = textViewCell;
}
return cell;
}
The problem could be this
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [arry count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
return 1;
}
instead
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
return [arry count];
}
You may swapped the return value of numberOfSectionsInTableView and numberOfSectionsInTableView
If this is correct, the below log will give you an idea.
NSLog(@"Section Number %d", indexPath.section);
NSLog(@"Row Number %d", indexPath.row);
This will log the row numbers as per the section.
Example: If you have a TableView with 2 sections and 6 rows (3 rows in each section),this will log as
Section Number 0
Row Number 0
Section Number 0
Row Number 1
Section Number 0
Row Number 2
Section Number 1
Row Number 0
Section Number 1
Row Number 1
Section Number 1
Row Number 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With