开发者

How can i reset the total rows of my table on the same button click at each time?

i am using UITableView with the following delegates.

tableView.delegate = self;
tableView.dataSource=self;

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

 {

    return 1;

}

// Customize the number of rows in the table view.

- (NSInteger)tableView:(UITableView *)tableView n开发者_C百科umberOfRowsInSection:(NSInteger)section {


    return 5;enter code here
}

it will set the number of Rows in a section at the loading time.

it will trigger the following delegate and i can do whatever i need with table cell.

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    if(indexPath.row == 0)
    {

However i need to create/reset the table rows dynamically(on a button click) and need to trigger

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

this delegate to set some datas to table cell.

how can i call this delegate in a button click.and also i need to reset the total rows of my table on the same button click at each time.

can any one help me to do it.


[self.tableView reloadData];

And they all lived happily ever after.


You need to change the dataSource of your table view and then call:

[tableView reloadData];

so in a button action you should:

-(void)buttonClicked{
     tableViewArray = ...//load array with new data;
     [self.tableView reloadData];
}


Have to set:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section      
{ 
    **return [tableViewArray count];**
}

- (void)buttonClicked
{
    tableViewArray = ... //load array with new data;
    [self.tableView reloadData];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜