Is the below code, I am loading data using printerArray = [SMPort searchPrinter];. This an expensive operating and locks the ui. Is there a way to do this asynchronously so I can show a loading indicator and when it is done show the data?
//
// SearchPrinterViewController.m
// PHP POS
//
// Created by Chris Muench on 3/12/14.
// Copyright (c) 2014 PHP Point Of Sale. All rights reserved.
//
#import "PrintingViewController.h"
#import "StarIO/SMPort.h"
#import "PrinterFunctions.h"
#interface PrintingViewController ()
#end
#implementation PrintingViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
uitableview_printerList.dataSource = self;
uitableview_printerList.delegate = self;
//Expensive operation. Could take up to 3-5 seconds
printerArray = [SMPort searchPrinter];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return printerArray.count + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (indexPath.row < printerArray.count)
{
PortInfo *port = [printerArray objectAtIndex:indexPath.row];
cell.textLabel.text = port.modelName;
NSString *detailText = [NSString stringWithFormat:#"%#(%#)", port.portName, port.macAddress];
cell.detailTextLabel.text = detailText;
}
else if (indexPath.row == printerArray.count)
{
cell.textLabel.text = #"Back";
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row < printerArray.count)
{
PortInfo *portInfo = [printerArray objectAtIndex:indexPath.row];
[PrinterFunctions PrintPHPPOSDocumentWithPortName:portInfo.portName textToPrint:self.textToPrint portSettings:#""];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
// This sends the fetching operation on the background
// You can put a loading indicator HERE BEFORE the dispatch.
// This sends the fetching operation on the background
[SVProgressHUD showWithStatus:#"Finding Printers" maskType:SVProgressHUDMaskTypeBlack];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
printerArray = [SMPort searchPrinter];
// Here you send tell the main thread to reload the table
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
[uitableview_printerList reloadData];
});
});
There are of course tons of other solutions, but this seems to me the minimal one for your case.
EDIT:
One thing I forgot: in order to make the printerArray writeable in the block, you have to add the keyword __block in front when you declare it.
EDIT: I put the final working code. I didn't need to add __block for some reaosn.
You can use a second NSOperationQueue or GCD (Grand Central Dispatch). The GCD approach is described above. Here is the NSOperation queue approach:
NSOperationQueue *printQueue = [[NSOperationQueue alloc] init];
[printQueue addOperationWithBlock:^{
// Background work
NSArray * array = [SMPort searchPrinter];
// Update the UI (in the main queue)
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
printerArray = [array copy];
[uitableview_printerList reloadData];
}];
}];
Take a look at this video:
https://developer.apple.com/videos/wwdc/2012/index.php?id=211
and this tutorial:
http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues
Related
I had a problem regarding how can I set my NSArray in completionHandler block. I successfully assign a value for NSArray in my completion block, but once I tried to NSLog NSArray value outside completion block it gave 0.
Here is my full code.
//
// HomeTVC.m
// ABOX
//
// Created by Zero on 11/18/15.
// Copyright © 2015 Zero. All rights reserved.
//
#import "HomeTVC.h"
#import "facebook.h"
#interface HomeTVC ()<UITableViewDataSource, UITableViewDelegate>
{
NSDictionary *userPageLikesParams;
NSArray *pagesInfo;
facebook *fb;
}
#end
#implementation HomeTVC
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
fb = [[facebook alloc] init];
userPageLikesParams = #{#"fields": #"about,name,created_time",#"limit": #"5"} ;
[fb getUserPagelikes:userPageLikesParams completionHandler:^(NSDictionary *pagesResult) {
pagesInfo = [[NSArray alloc] init];
pagesInfo = pagesResult[#"data"];
// NSArray *p = pagesResult[#"data"];
// [self pages:p];
}];
}
//- (void)pages:(NSArray*)pageInfo {
//
// self.pagesInfo = pageInfo;
// NSLog(#"fb pages result ayam : %#", self.pagesInfo[0]);
// NSLog(#"array counzz : %d", (int)self.pagesInfo.count);
//}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// here I got 0, how can I solve this problem?
NSLog(#"table count : %d", (int)pagesInfo.count);
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
// Configure the cell...
return cell;
}
#end
Thanks in advance.
Reload your table view when the completion block finishes up and you should see your pagesInfo array populated and returning a count.
As per #michal, you should reload your tableView below like this:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
fb = [[facebook alloc] init];
userPageLikesParams = #{#"fields": #"about,name,created_time",#"limit": #"5"} ;
[fb getUserPagelikes:userPageLikesParams completionHandler:^(NSDictionary *pagesResult)
{
pagesInfo = pagesResult[#"data"];
[yourTableViewObj reloadData];
// NSArray *p = pagesResult[#"data"];
// [self pages:p];
}];
}
Hope it will help.
I'm stuck with parse PFIMageView via URL. I already wrote one question, moved little bit but the app still doesn't work. I put run and got this error, nothing loads.
image with errors : http://postimg.org/image/jys3hqegt/
previous question: Parse.com adding images via URL
#interface TableViewController ()
#end #implementation TableViewController
#synthesize colorsTable;
- (void) retrieveFromParse {
PFQuery *retrieveColors = [PFQuery queryWithClassName:#"Hracky1"];
[retrieveColors findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
colorsArray = [[NSArray alloc] initWithArray:objects];
}
[colorsTable reloadData];
}];
[self.colorsTable reloadData];
[self.refreshControl endRefreshing]; }
- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self; }
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:#selector(retrieveFromParse)];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl = refreshControl;
[refreshControl addTarget:self action:#selector(retrieveFromParse) forControlEvents:UIControlEventValueChanged]; }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated. }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return colorsArray.count; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"colorsCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
PFObject *tempObject = [colorsArray objectAtIndex:indexPath.row];
[cell.imageview setFile: [tempObject objectForKey:#"ImageURL"]];
[cell.imageview loadInBackground];
cell.cellTitle.text = [tempObject objectForKey:#"cellTitle"];
cell.cellDescript.text = [tempObject objectForKey:#"cellDescript"];
return cell; }
#end
Do you check the object of the line: [tempObject objectForKey:#"ImageURL"]?
I think you can trace the URL of the object to find some informations.
C/xcode geeks!
I have been struggling with this error for hours now, and I don't seem to find the solution, although it seems as many people have had the exact same problem.
See code:
//
// ListViewController.m
// Puns
//
// Created by Amit Bijlani on 12/13/11.
// Copyright (c) 2011 Treehouse Island Inc. All rights reserved.
//
#import "ListViewController.h"
#import "BlogPost.h"
//#import "Pun.h"
#import "PunsTableViewCell.h"
#import "DetailViewController.h"
#implementation ListViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
#pragma mark - Segue
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(#"0");
if ( [[segue identifier] isEqualToString:#"ShowMenu"] ){
NSLog(#"1");
DetailViewController *dvc = (DetailViewController *)[segue destinationViewController];
dvc.menu = [self.blogPosts objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
}
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// GET WEB DATA SOURCE (JSON)
// The url
NSURL *blogURL = [NSURL URLWithString:#"http://constantsolutions.dk/json.html"];
// The data
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
// Error variable
NSError *error = nil;
// jsonData to serialization
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
// Get array 'posts'
self.blogPosts = [NSMutableArray array];
NSArray *blogPostsArray = [dataDictionary objectForKey:#"posts"];
for (NSDictionary *bpDictionary in blogPostsArray) {
// Get title
// Will only retrieve data, if TITLE exists
BlogPost *blogPost = [BlogPost blogPostWithTitle:[bpDictionary objectForKey:#"title"]];
// Get the content
blogPost.content = [bpDictionary objectForKey:#"content"];
// Get thumbnail
blogPost.thumbnail = [bpDictionary objectForKey:#"thumbnail"];
// Get date
blogPost.date = [bpDictionary objectForKey:#"date"];
// Get price
blogPost.price = [bpDictionary objectForKey:#"price"];
// Add the object to blogPosts array
[self.blogPosts addObject:blogPost];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.blogPosts count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"PunTableViewCell";
PunsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[PunsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
BlogPost *blogPost = [self.blogPosts objectAtIndex:indexPath.row];
cell.menuTitle.text = blogPost.title;
cell.menuContent.text = blogPost.content;
if([blogPost.price length] == 0) {
[cell.menuPrice setHidden:YES];
} else {
cell.menuPrice.text = blogPost.price;
}
return cell;
}
#end
As you can see, I have implented NSLog() inside the prepareForSegue, but it is not triggered.
Do you guys have any idea what I am doing wrong? I am pretty new to this, so I still haven't found out this whole iPhone development thing. So bare over with me if the solution is simple :o).
Thanks in advance!
You have a name for the segue, so does that mean you created it by dragging from a button or table view cell to the other view controller and then selected it and named it in xcode? if you are programmatically changing the view it wont be called but you can manually call a method before swapping views to prepare
I had a similar issue in going about sharing information in ios between views where the answer may be helpful.
In particular from the answer on that post where he says:
"in your .m file you would trigger you segue - maybe on a button or some action. sounds like you already have this:"
[self performSegueWithIdentifier:#"viewB" sender:self];
--
Swapping your segue name in of course.
I'm trying to load Lazy Tableview in a custom cell in storyboard, but the table view just looks blank:
This is the source code:
LazyLoadTable.m
#import "CellData.h"
#import "LazyLoadTableView.h"
#import "CustomCell.h"
#import "ParseOperation.h"
#import "ImageDownloader.h"
#define kCustomRowHeight 157
#define kCustomRowCount 1
static NSString *const xmlDataUrl =
#"http://itunes.apple.com/us/rss/topfreeapplications/limit=300/xml";
#interface LazyLoadTableView ()
#end
#implementation LazyLoadTableView
#synthesize tableElements;
#synthesize queue;
#synthesize connection;
#synthesize xmlData;
#synthesize tView;
#synthesize imageDownloadsInProgress;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.tableElements=[[NSMutableArray alloc] init];
self.imageDownloadsInProgress = [NSMutableDictionary dictionary];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title=#"Menu";
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:xmlDataUrl]];
self.connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
// Test the validity of the connection object.
NSAssert(self.connection != nil, #"Failure to create URL connection.");
// show in the status bar that network activity is starting
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int count = [tableElements count];
// ff there's no data yet, return enough rows to fill the screen
if (count == 0)
{
return kCustomRowCount;
}
return count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// customize the appearance of table view cells
static NSString *placeholderCellIdentifier = #"PlaceholderCell";
// add a placeholder cell while waiting on table data
int nodeCount = [self.tableElements count];
if (nodeCount == 0 && indexPath.row == 0)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:placeholderCellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:placeholderCellIdentifier];
cell.detailTextLabel.textAlignment = NSTextAlignmentCenter ;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.detailTextLabel.text = #"Loading…";
return cell;
}
static NSString *CustomCellIdentifier = #"CustomCellIdentifier";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CustomCell class]])
cell = (CustomCell *) [nib objectAtIndex:0];
}
// Leave cells empty if there's no data yet
if (nodeCount > 0)
{
// Set up the cell...
CellData *cellData = (self.tableElements)[indexPath.row];
cell.name.text = cellData.name;
// Only load cached images; defer new downloads until scrolling ends
if (!cellData.icon)
{
if (self.tView.dragging == NO && self.tView.decelerating == NO)
{
[self startIconDownload:cellData forIndexPath:indexPath];
}
// if a download is deferred or in progress, return a placeholder image
cell.itemImage.image = [UIImage imageNamed:#"Placeholder.png"];
}
else
{
cell.itemImage.image = cellData.icon;
}
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return kCustomRowHeight;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
self.xmlData = [NSMutableData data]; // start off with new data
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.xmlData appendData:data]; // append incoming data
}
#pragma mark -
#pragma mark NSURLConnection delegate methods
- (void)handleError:(NSError *)error
{
NSString *errorMessage = [error localizedDescription];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Cannot Show Data"
message:errorMessage
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if ([error code] == kCFURLErrorNotConnectedToInternet)
{
// if we can identify the error, we can present a more precise message to the user.
NSDictionary *userInfo = #{NSLocalizedDescriptionKey: #"No Connection Error"};
NSError *noConnectionError = [NSError errorWithDomain:NSCocoaErrorDomain
code:kCFURLErrorNotConnectedToInternet
userInfo:userInfo];
[self handleError:noConnectionError];
}
else
{
// otherwise handle the error generically
[self handleError:error];
}
self.connection = nil; // release our connection
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
self.connection = nil; // release our connection
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// create the queue to run our ParseOperation
self.queue = [[NSOperationQueue alloc] init];
ParseOperation *operation = [[ParseOperation alloc] initWithData:self.xmlData delegate:self];
[queue addOperation:operation]; // this will start the "ParseOperation"
self.xmlData = nil;
}
- (void)didFinishParsing:(NSArray *)cellDataList
{
[self performSelectorOnMainThread:#selector(handleLoadedApps:) withObject:cellDataList waitUntilDone:NO];
self.queue = nil; // we are finished with the queue and our ParseOperation
}
- (void)parseErrorOccurred:(NSError *)error
{
[self performSelectorOnMainThread:#selector(handleError:) withObject:error waitUntilDone:NO];
}
- (void)handleLoadedApps:(NSArray *)loadedCellData
{
[self.tableElements addObjectsFromArray:loadedCellData];
// tell our table view to reload its data, now that parsing has completed
[self.tView reloadData];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)startIconDownload:(CellData *)cellData forIndexPath:(NSIndexPath *)indexPath
{
ImageDownloader *imageDownloader = imageDownloadsInProgress[indexPath];
if (imageDownloader == nil)
{
imageDownloader = [[ImageDownloader alloc] init];
imageDownloader.cellData = cellData;
imageDownloader.indexPathInTableView = indexPath;
imageDownloader.delegate = self;
imageDownloadsInProgress[indexPath] = imageDownloader;
[imageDownloader startDownload];
}
}
// this method is used in case the user scrolled into a set of cells that don't have their app icons yet
- (void)loadImagesForOnscreenRows
{
if ([self.tableElements count] > 0)
{
NSArray *visiblePaths = [self.tView indexPathsForVisibleRows];
for (NSIndexPath *indexPath in visiblePaths)
{
CellData *cellData = (self.tableElements)[indexPath.row];
if (!cellData.icon) // avoid the app icon download if the app already has an icon
{
[self startIconDownload:cellData forIndexPath:indexPath];
}
}
}
}
// called by our ImageDownloader when an icon is ready to be displayed
- (void)imageDidLoad:(NSIndexPath *)indexPath
{
ImageDownloader *imageDownloader = imageDownloadsInProgress[indexPath];
if (imageDownloader != nil)
{
CustomCell *cell = (CustomCell *)[self.tView cellForRowAtIndexPath:imageDownloader.indexPathInTableView];
// Display the newly loaded image
cell.itemImage.image = imageDownloader.cellData.icon;
}
}
#pragma mark -
#pragma mark Deferred image loading (UIScrollViewDelegate)
// Load images for all onscreen rows when scrolling is finished
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
[self loadImagesForOnscreenRows];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self loadImagesForOnscreenRows];
}
#end
CustomCell.m
#import "CustomCell.h"
#implementation CustomCell
#synthesize itemImage;
#synthesize name;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
Didn't read through all that code but it looks like you are trying to lazy load an image with some text. I highly recommend using SDWebImage for the lazy loading. It's simple and very straightforward to set up.
While I was surfing over the Internet I've found a lot of examples how to load array in the TableViewController, but none of them helped me!
Couldn't you help me to find what is wrong in my code ?
Thank you in advance!!!
#import "Images.h"
#import "AFNetworking.h"
#import "HTMLparser.h"
#interface Images ()
#end
#implementation Images
#synthesize data;
#synthesize textFromVC1;
#synthesize tableView;
#synthesize so2;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.data = [[NSMutableArray alloc]init];
NSError *error = nil;
NSString *so = [#"http://" stringByAppendingString: self.textFromVC1];
NSURL *url = [[NSURL alloc]initWithString:so];
NSString *str=[[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
HTMLParser *parser = [[HTMLParser alloc] initWithString:str error:&error];
if (error) {
NSLog(#"Error: %#", error);
[parser release];
parser = nil;
return;
}
HTMLNode * body = [parser body];
NSArray *inputs = [body findChildTags:#"img"];
for (HTMLNode *input in inputs) {
NSString *links = [input getAttributeNamed:#"src"];
NSString *so1 = [so stringByAppendingString: #"/"];
so2 = [so1 stringByAppendingString: links];
[self.data addObject:so2];
NSLog(#"%#", data);
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
}];
[operation start];
}
[self.tableView reloadData];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[self setTableView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = #"LinkID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
cell.textLabel.text = [self.data objectAtIndex:indexPath.row];
[self.tableView reloadData];
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}
- (void)dealloc {
[tableView release];
[super dealloc];
}
#end
well 1) numberOfSections is 0. to see something it should be one IIRC
think thats it but havent double checked
Assuming your data array is built up correctly, your mistake in is your numberOfSections methods. Currently, it returns 0, which tells the UITableView that there are currently no sections to be displayed… ever.
You can either return 1; there or remove the entire method altogether. The default implementation, which you inherit from UITableViewController, also returns 1 by default.
My advice would be to remove the method, as that keeps your own code cleaner. You can always implement it in a later stage, when you might actually need it.