Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

indexPath returns 0 in all rows

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

NSLog(@"%@", 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}

cellForRowAtIndexPath

- (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;
}
like image 860
user3837816 Avatar asked Dec 05 '25 19:12

user3837816


2 Answers

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];
    }
like image 107
Rajesh Avatar answered Dec 07 '25 07:12

Rajesh


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
like image 21
Shamsudheen TK Avatar answered Dec 07 '25 07:12

Shamsudheen TK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!