Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // TrackeesViewController.m
- #import "TrackeesViewController.h"
- #import "SFHttpRequestDispatcher.h"
- #import "NSURLConnection-block.h"
- #import "SFHttpRequestDispatcher.h"
- #import "Util.h"
- @implementation TrackeesViewController
- @synthesize trackees;
- - (void) showBusyDialog{
- HUD = [[MBProgressHUD alloc] initWithView:self.view];
- [self.view addSubview:HUD];
- HUD.delegate = self;
- HUD.labelText = @"Loading Trackees...";
- [HUD show:YES];
- }
- -(void)setTrackeesFromBG:(NSArray*)theTrackees{
- if([NSThread currentThread] != [NSThread mainThread]){
- [self performSelectorOnMainThread:_cmd withObject:theTrackees waitUntilDone:YES];
- return;
- }
- NSArray* mainThreadTrackees = [theTrackees copy];
- self.trackees = mainThreadTrackees;
- [mainThreadTrackees release];
- }
- -(void)viewDidLoad{
- [self showBusyDialog];
- User *user = [[[User alloc] initWithPhoneNumber:@"07032314287"
- password:@"testtest"]autorelease];
- SFHttpRequestDispatcher *dispatcher = [Util dispatcherForGetTrackersForUser:user];
- [NSURLConnection asyncRequest:[dispatcher doGetOrPost]
- success:^(NSData *data, NSURLResponse *response) {
- NSLog(@"Successfully Got Trackers");
- NSArray *jsonArray = [data objectFromJSONData];
- self.trackees = jsonArray;
- [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
- NSLog(@"%@", [jsonArray description]);
- //-objectFromJSONData should return an autoreleased array, no need to release here
- //[jsonArray release];
- [self performSelectorOnMainThread:@selector(hudWasHidden:) withObject:HUD waitUntilDone:NO];
- }
- failure:^(NSData *data, NSError *error){
- NSLog(@"Failure Getting Trackers");
- [self performSelectorOnMainThread:@selector(hudWasHidden:) withObject:HUD waitUntilDone:NO];
- }
- ];
- }
- -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return [self.trackees count];
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString* TrackeeString = @"TrackeeString";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TrackeeString];
- if(nil == cell){
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TrackeeString]autorelease];
- }
- NSUInteger row = [indexPath row];
- NSString *trackeeJSON = [trackees objectAtIndex:row];
- Person *person = [Person fromJSON:trackeeJSON];
- cell.textLabel.text = person.phoneNumber;
- return cell;
- }
- #pragma mark -
- #pragma mark MBProgressHUDDelegate methods
- - (void)hudWasHidden:(MBProgressHUD *)hud {
- // Remove HUD from screen when the HUD was hidded
- [HUD removeFromSuperview];
- [HUD release];
- HUD = nil;
- }
- @end
- //error message below:
- 2011-09-06 11:33:14.492 mtracker[28687:207] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:5678
- sharedlibrary apply-load-rules all
Add Comment
Please, Sign In to add comment