Reputation: 724
I am making an inbox module in my app. I want to ask that i want to create a label programaticaly in UITableView after laoding data from Json. through which we click and get more data? How it can be done? Example like in facebook, we click on messages and by moving down we click on load more messages ??? on load more message label i ahve to send another call to load more message.
Upvotes: 1
Views: 322
Reputation: 9589
For that you can set as a button.If you click that button in tableview,you can get more data or else you can get data step by step like ten by ten data.
Create Custom Cell and Set the Button in Custom Cell also give name as btnLoadMore
In header file
@interface myViewController : UIViewController {
int loadMoreTableInt;
int paginationInt;
}
In .m file
- (void)viewDidLoad {
[super viewDidLoad];
loadMoreTableInt = 0;
paginationInt = 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
customCell *cell=(customCell*)[tableView dequeueReusableCellWithIdentifier:@"Reuse"];
NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"customCell" owner:self options:nil];
if(cell == nil) {
cell=[nib objectAtIndex:0];
}
if(loadMoreTableInt-1> indexPath.row) {
cell.labelName.text = [NSString stringWithFormat:@"%@",[modelRoot.arrayName objectAtIndex:indexPath.row]];
} else {
if(cell == nil) {
cell=[nib objectAtIndex:1];
}
[cell.btnLoadMore setTitle:[NSString stringWithFormat:@"Load More "] forState:UIControlStateNormal];
cell.btnLoadMore.tag=indexPath.row;
cell.accessoryType=UITableViewCellAccessoryNone;
[cell.btnSeeMorebtnLoadMore addTarget:self action:@selector(loadmoreButtonAction:) forControlEvents:UIControlEventTouchUpInside];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
In loadmoreButtonAction give the code like this
-(void)loadmoreButtonAction:(id)sender {
@try {
UIButton *btn=(id)sender;
paginationInt=paginationInt+1;
[tableview reloadData];
CGPoint point;
point.x=40;
point.y=btn.tag*53;
NSIndexPath *path = [tableview indexPathForRowAtPoint:point];
[tableview scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:NO];
}@catch (NSException *exception) {
}
}
Upvotes: 0
Reputation: 532
Ok so you're gonna have to hack this all together. This is the usual approach to get a "Load more data" cell
on your uitableview
Methods Needed
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return dataRows+1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//after setting tableviewcell
if(indexPath.row==dataRows){
cell.textLabel.text=@"Load More Rows";
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==dataRows){
//there you can write code to get next rows
}
}
Ok this is where the hacking will have to begin. Look at this CODE.
The method that seems to be most important is
- (void)reloadTableView:(int)startingRow
Upvotes: 1