Hello friends
If you are loading to a specific count data to a UITableView and you need to add more data on "refresh"(i.e PULL TO REFRESH) then I have some help here.
Add protocol to Landing screen class and declare a method name :
-(void)responseDict:(id)response tagValue:(int)tagValue;
LandingScreenAgentClass
-(void)gettingMoreDetail:(NSString *)make andStart:(NSString *)start andCount:(NSString *)count andModel:(NSString *)model andYear:(NSString *)year andReviewId:(NSString *)reviewId andladingArrayCount:(int)arrayCount delegate:(UIViewController<LandingScreenDelegate>*)del
{
tagValue=2;
self.delegate = del;
// start=(NSString *)arrayCount;
NSString *urlString=[NSString stringWithFormat:@"%@%@?make=%@&reviewId=%@&start=%d&count=%@",BASE_URL_FOR_USER,BASE_URL_FOR_FETCHING_REVIEWS,@"dukati",reviewId,arrayCount,count];
NSLog(@"url is %@",urlString);
ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:urlString]];
[request setDelegate:self];
[request setTimeOutSeconds:60];
[request setDidFailSelector:@selector(setDidFailSelectorLanding:)];
[request setDidFinishSelector:@selector(setDidFinishSelectorLanding:)];
[request startAsynchronous];
}
ViewControllerImplementation
pragma mark LandingScreenDelegates
-(void)responseDict:(id)response tagValue:(int)tagValue
{
NSDictionary *dict = (NSDictionary *)response;
NSLog(@"dictdict====landing========%@",dict);
NSDictionary *status=[dict objectForKeyWithNullCheck:@"status"];
NSString *statuscode = [status objectForKeyWithNullCheck:@"code"];
NSString *description =[status objectForKeyWithNullCheck:@"description"];
if ([statuscode isEqualToString:STATUS_CODE]&&[description isEqualToString:STATUS_DESCRIPTION])
{
NSArray *dictReview = [dict objectForKeyWithNullCheck:@"review"];
NSMutableArray *dictArrayDelegate=[NSMutableArray new];
for (NSDictionary *dictValue in dictReview)
{
ReviewModel *reviewModal=[[ReviewModel alloc]initWithDictionary:dictValue];
[dictArrayDelegate addObject:reviewModal];
}
NSLog(@"DICT ARRAY IS %@",dictArrayDelegate);
if (dictArray==nil) {
dictArray = [[NSMutableArray alloc]init];
}
[dictArray addObjectsFromArray:dictArrayDelegate];
// dictArray = [[NSArray alloc]initWithArray:dictArrayDelegate];
// [activityIndicator setHidden:YES];
[carTable reloadData];
}
else if([statuscode isEqualToString:STATUS_FAILED])
{
[Utils showAlert:@"Messages" message:@"Nothing fetched"];
}
atuscode isEqualToString:STATUS_FAILED])
{
[Utils showAlert:@"FAIL" message:@"Failed Hit"];
}
}
}
For making a pull to refresh you need to user Scroll view delegates
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSLog(@"cartablecobntentoffset%f",carTable.contentOffset.y);
NSLog(@"scrollview frame %f",scrollView.frame.size.height);
NSLog(@"MIXED %f",((carTable.contentSize.height+carTable.frame.size.height)-10));
if (carTable.contentOffset.y>((carTable.contentSize.height+carTable.frame.size.height)-700))
{
[carTable setScrollEnabled:NO];
[activityIndicator setHidden:YES];
[activityIndicator startAnimating];
NSLog(@"car table is %f",carTable.contentOffset.y);
LandingScreenSeverAgent *land=[[LandingScreenSeverAgent alloc]init];
[land gettingMoreDetail:@"Toyota" andStart:@"" andCount:@"10" andModel:@"" andYear:@"" andReviewId:@"" andladingArrayCount:dictArray.count delegate:self];
}
[carTable setScrollEnabled:YES];
if (carTable.contentOffset.y<700) {
// [activityIndicator removeFromSuperview];
// [activityIndicator setHidden:YES];
NSLog(@"less contemt off set");
}
}
I hope this helps you.
0 Comment(s)