如何使用label&创建自定义单元格目标文本域c

时间:2016-03-08 06:56:25

标签: ios objective-c uitextfield custom-cell uitableview

我已经采取标题部分说了

星期一,星期二,星期三......星期天等等我还添加了" +"部分标题后的按钮&在该按钮上添加了操作

下面是代码和截图。

Before:7
Array ( [0] => Array ( [customer_name] => User [profile_image] => http://pet.huarisnaque.com/pet/upload/90113.png [jid] => user128@canopus-pc [customer_id] => 128 [phone] => 4784784784 ) [1] => Array ( [customer_name] => Khatru [profile_image] => http://smartpetmanagement.com/upload/61694.png [jid] => khatru321@canopus-pc [customer_id] => 321 [phone] => 9686838386 ) [2] => Array ( [customer_name] => pppoo [profile_image] => http://smartpetmanagement.com/upload/35210.png [jid] => yyy329@canopus-pc [customer_id] => 329 [phone] => 9525538835 ) [3] => Array ( [customer_name] => Xitxitx [profile_image ] => [jid] => xitxitx330@canopus-pc [customer_id] => 330 [phone] => 6535383535 ) [4] => Array ( [customer_name] => The Following Document yf [profile_image] => http://smartpetmanagement.com/upload/13712.png [jid] => the following document yf589@canopus-pc [customer_id] => 589 [phone] => 9535383535 ) [5] => Array ( [customer_name] => Pet [profile_image ] => [jid] => pet590@canopus-pc [customer_id] => 590 [phone] => 6560530537 ) [6] => Array ( [customer_name] => Sanjay Pra [profile_image ] => [jid] => sanjay pra599@canopus-pc [customer_id] => 599 [phone] => 2828282822 ) ) 

Match INDEX on result 0 == customerlist 2
Match INDEX on result 1 == customerlist 5

After: 5
Array ( [0] => Array ( [customer_name] => User [profile_image] => http://pet.huarisnaque.com/pet/upload/90113.png [jid] => user128@canopus-pc [customer_id] => 128 [phone] => 4784784784 ) [1] => Array ( [customer_name] => Khatru [profile_image] => http://smartpetmanagement.com/upload/61694.png [jid] => khatru321@canopus-pc [customer_id] => 321 [phone] => 9686838386 ) [3] => Array ( [customer_name] => Xitxitx [profile_image ] => [jid] => xitxitx330@canopus-pc [customer_id] => 330 [phone] => 6535383535 ) [4] => Array ( [customer_name] => The Following Document yf [profile_image] => http://smartpetmanagement.com/upload/13712.png [jid] => the following document yf589@canopus-pc [customer_id] => 589 [phone] => 9535383535 ) [6] => Array ( [customer_name] => Sanjay Pra [profile_image ] => [jid] => sanjay pra599@canopus-pc [customer_id] => 599 [phone] => 2828282822 ) )

this is i have made format of design

现在我必须创建单元格,当我点击" +"按钮,所以请帮助我。

2 个答案:

答案 0 :(得分:4)

你可以这样做,

首先,您必须使用数组来动态操作数据源。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section ==0) {
        return 0;
    }else{
        return numberOfRowNeedToDisplay; //Take global int variable
    }
}

在按钮操作AddTimeSlot中:

-(void)addTimeSlot:(id)sender {

//If you want to add cell to section
NSMutableArray *arrayIndexPathsToBeAdded = [[NSMutableArray alloc] init];

    for (int i = 0; i < <numberOfCellsYouWantToAdd>; i++) {

       [arrayIndexPathsToBeAdded addObject:[NSIndexPath indexPathForRow:i inSection:view.tag]];

    }

    numberOfRowNeedToDisplay = <numberOfCellsYouWantToAdd>;

    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:arrayIndexPathsToBeAdded withRowAnimation:UITableViewRowAnimationRight];

    [self.tableView endUpdates];

//If you want to remove cells
NSMutableArray *arrayIndexPathsToBeRemoved = [[NSMutableArray alloc] init];

    for (int i = 0; i < <numberOfCellsYouWantToRemove>; i++) {
        [arrayIndexPathsToBeRemoved addObject:[NSIndexPath indexPathForRow:i inSection:sectionIndexToBeExpanded]];
    }

    numberOfRowNeedToDisplay = <numberOfCellsYouWantToRemove>;

    [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:arrayIndexPathsToBeRemoved withRowAnimation:UITableViewRowAnimationLeft];

}

这就是我所做的:

enter image description here

答案 1 :(得分:0)

请阅读评论文字。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

  /** should be change in dynamically
    maintain array for every section rows
    return row count accordint to section
   **/
}

#pragma mark - Private methods

- (void)AddTimeSlot:(UIButton *)sender {

    int sectionNo = sender.tag;
    // Get you section rowArray(DATASOURCE) and insert you detaisl
    // then add UI

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

    [tableView beginUpdates];
    [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
    [tableView endUpdates];
}
相关问题