Divide the `UITableViewCell` into parts

I am creating an application in which I have to divide the cell into three parts. For example, I have to specify the title in one cell and immediately display the corresponding data.

How can i do this?


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 

{

 static NSString *CellIdentifier = @"Cell"; myappAppDelegate *mydelegate=(myappAppDelegate *)[[UIApplication sharedApplication]delegate]; database *objdata =[mydelegate.myarray objectAtIndex:indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryNone; if (indexPath.row == 0) { UILabel *temp = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 200, 44)]; temp.text =@ "Main Balance"; temp.backgroundColor = [UIColor clearColor]; temp.font = [UIFont systemFontOfSize:19]; [cell addSubview:temp]; UILabel *temp1 = [[UILabel alloc] initWithFrame:CGRectMake(240, 0, 50, 44)]; temp1.text =@ "2000"; temp1.backgroundColor = [UIColor clearColor]; temp1.font = [UIFont systemFontOfSize:19]; [cell addSubview:temp1]; else if(indexPath.row==1) { UILabel *temp = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 108, 44)]; temp.text =@ "Income"; temp.backgroundColor = [UIColor clearColor]; temp.font = [UIFont systemFontOfSize:19]; [cell addSubview:temp]; } else { UILabel *temp = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 108, 44)]; temp.text =[NSString stringWithFormat:@"%d",objdata.amount]; temp.backgroundColor = [UIColor clearColor]; temp.font = [UIFont systemFontOfSize:19]; [cell addSubview:temp]; } enter code here 

On the main screen, I create the One Main Blaance text box and two buttons, such as Earnings, Expenses, and Last Button. When I click "Income", another view is displayed, in which "Add income in the text box" and one button "Add to the main balance". I type the amount of income in this text box and then on β€œSave”, it will save it in the database, I do the same for β€œExpenses”, then I click On the main balance button the amount is added or subtracted in the text box of the main balance, which I showing on the main screen. Then click the "Final Display" button on the main screen, it will display three labels "Revenue", "Expense", "Main Balance" .. in TableView.I get the value Under Income and Expense But it only displays the initial value, which I entered into the database. Development time on request.

My question is: - Suppose I add 4 data, then the final display will display all this data. Even if I add more data, they will also be shown on the final display .... I hope U can get my point..please Direct me, I'm so confused.

+4
source share
4 answers

You can add 3 shortcuts to each cell. And assign their value in a UITableView. This is the only easy way to do this.

You must define labels in your UITableViewCell declaration. After that, you can assign values ​​where you declare your UITableView.

Thus, each of your cells will contain 3 labels, which you can place anywhere.

+1
source

Use this code to help you.

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"ShowMoreCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell = [self getCellContentView:CellIdentifier]; UILabel *lbl1 = (UILabel *)[cell viewWithTag:1]; [lbl1 setText:@"Label1"]; UILabel *lbl2 = (UILabel *)[cell viewWithTag:2]; [lbl2 setText:@"Label3"]; UILabel *lbl3 = (UILabel *)[cell viewWithTag:3]; [lbl3 setText:@"Label3"]; return cell; } - (UITableViewCell *)getCellContentView:(NSString *)cellIdentifier { UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease]; cell.backgroundColor=[UIColor clearColor]; CGRect lbl1Rect = CGRectMake(20, 5, 280, 30); CGRect lbl2Rect = CGRectMake(20, 35, 280, 30); CGRect lbl3Rect = CGRectMake(20, 70, 280, 30); UILabel *lbl1 = [[UILabel alloc] initWithFrame:lbl1Rect]; lbl1.tag=1; lbl1.font=[UIFont fontWithName:@"Helvetica" size:13]; lbl1.backgroundColor=[UIColor clearColor]; [cell.contentView addSubview:lbl1]; [lbl1 release]; UILabel *lbl2 = [[UILabel alloc] initWithFrame:lbl2Rect]; lbl2.tag=1; lbl2.font=[UIFont fontWithName:@"Helvetica" size:13]; lbl2.backgroundColor=[UIColor clearColor]; [cell.contentView addSubview:lbl2]; [lbl2 release]; UILabel *lbl3 = [[UILabel alloc] initWithFrame:lbl3Rect]; lbl3.tag=1; lbl3.font=[UIFont fontWithName:@"Helvetica" size:13]; lbl3.backgroundColor=[UIColor clearColor]; [cell.contentView addSubview:lbl3]; [lbl3 release]; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; } 
+5
source

if you are using a UITableView , then create a section for each information and make three lines in each section.

or

create a custom cell in which there are three rows of UILabels in each row.

+1
source

you can add three uiviews for

-2
source

Source: https://habr.com/ru/post/1395592/


All Articles