Display Alert if tableView has no Results - iphone

I previously thought I could answer this question with a simple array count (my mistake). I am trying to display an alert to the user id a tableView has no results. I cannot simply place the count in the viewDidAppear method because the web query that populates the JSON and tableView takes a few seconds to populate. I cannot simply place this in:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows]
lastObject]).row){
//loading complete
}
}
Because nothing gets called in this method if there are no results. Does anyone have any recommendations for this - been searching for over 4 hours and have pulled nearly all my hair out.
Please feel free to un-downvote this questions if it has been made more suitable for SO - this questions massive downvotes have cost me my ability to ask questions...

NSInteger count = [array count];

NSlog("array count : %d",[array count];
This will give you array count in your console.

You cannot check the row count in viewDidAppear because an asynchronous NSURLConnection is used to fetch the JSON data that populates the table view.
The correct way is to call reloadData in connectionDidFinishLoading, after you have updated your data source with the response from the URL request. At that point you know if the number of rows is zero or not, and there is no need to wait for the table view update to complete.

Related

Show Loading Message if table takes a long time

I want to display a "Loading" message if my table is not filled with all the information in 3 seconds. Here is what I want my table to do:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//First time
UITableView *cell = [tableView cellForRowAtIndexPath:indexPath];
//Configure table
//Second Time
}
NSTimeInterval timeDifference = [firstTime timeIntervalSinceDate:secondTime];
if (timeDifference == 3 seconds){
//Display Loading message
}
I think you're approaching the problem wrong in your question. Instead of only showing a loading state if your data loading is taking too long, try always showing the loading state UNTIL the data load operation has completed (hopefully on a background thread which will allow your main UI thread to actually show the loading UI). There are a number of ways to achieve this, the best way for you will depend on your personal preference and existing code.

how to get respected person details saved in arrays from selected value in table view

i am having 3 arrays with info regarding peoples.
one array is with name,second array with email,third array with phone number.
eg:{jon,Willems...},{jon#example.com,Willems#example.com...},{123456,123456,...}
I need to display agent names in table.
when ever i selects people name in table i need to retrieve that particular person email and phone number.
how can i done,can any one please post some code or tutorial.
Thank u in advance.
In didSelectRowAtIndextPath get the indexPath value
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[email objectAtIndex:indexPath.row];
[phoneNumber objectAtIndex:indexPath.row];
}
EDIT:
The Above code assumes that a user is associated with a single email, phone number
If a user name is associated with many email, phone numbers use NSDictionary or Custom Object.

Why are multiple touches causing my iPhone app to crash?

In my app, I am getting the row index as the user taps on the row or selected row. But if a row is tapped twice, my app crashes.
What could be causing this behavior, and how can I fix it? Here's the code I'm using:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
abc *xyz = [[abc alloc] init];
dcs = [allHadits objectAtIndex:indexPath.row];
hk = dcs.kokid;
[dcs release];
}
Do you mean tapping on the same row twice makes it crash? If so, it might be because of the [dcs release]. I don't know what dcs is (unless that's supposed to be xyz) but grabbing a pointer to the object in the array and then calling release on it might be releasing the object in the array, making it crash next time the row is hit. Delete the [dcs release] and see if it still crashes. My memory management isn't the greatest though so I could be wrong.
Don't release dcs. Why are your variables named so poorly?

parsing xml for iphone

can i parse my XML in this method
Blockquote
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// here some instance of XMLparser ??
}
Blockquote
like whenevrr uer press table cell then for detail view i want to pull data at that time only and for that specfic only as i have 8k data so i dont want to parse other data
You have to be careful about runtime performance. If the parse runs really fast, like 50 - 100 ms, it is kind of acceptable performance for me. If it runs too long, like > 1 second, it is absolutely sure that you shouldn't put parsing in that method.
If you talk about pulling data from network and parsing it, it is quite risky and slow for me. If you use synchronous, it will block the UI, if you use asynchronous, what will happen when user going to detail view and don't see anything. If it is just like update old data, it is acceptable to use asynchronous
I've used TouchXML and NSURLConnection in the past for doing these kind of things. You'll probably want to use the asynchronous methods so you don't block the GUI thread during the fetches.
yes i am calling in
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch(indexPath.section)
{
case 2:
pragma mark postcode
cell.textLabel.text = aBook.telnumber;
NSLog(#"String = %#",aBook.tel);
NSLog(#"String = %#",aBook.telnumber);
}
tel was defined in sql so that was working correct
now in xml i hav changes that tel to telnumber thats it and commnet that aBook.tel in sql query nothing else
but now its null ... do i need to add xmlparsed elemtns to books in didEndElement in PArsing class??

Limiting App for Free Version (In App Purchase)

I want to set up my app as a free version and unlock it with in app purchases, just so I'll get more exposure. The free version should be limited and therein lies my problem.
My app uses core data heavily and to make the free version, I just want to limit all records displayed to 1 row in each tableview, or if anybody else has any better ideas, those'd work too.
I've been trying to set my numberOfRowsInSection to return 1, but everytime I add something I get a range exception as I'm using a fetchedResultsController. Any ideas?
Here's my section and row code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [[fetchedResultsController sections] count];}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];}
Use -setFetchLimit: on the NSFetchRequest. If you set it to 1 then the NSFetchResultController will only give you a single row back.
You could handle this in your didSelectRow method. If the row isn't 0, throw an UIAlertView that explains how you can buy the app to use the full version. This will also show users that more content exists. I seem to recall Apple not liking advertisements for full versions, but I've also seen plenty of it, so I guess it's OK now.
i'm also doing as Marcus has recommended above:
if(!appDelegate.fullVersion){
[fetchRequest setFetchLimit:10];
NSLog(#"only fetching 10 as not full version");
}
I check for full version on appDidFinishLaunching and maintain a BOOL in the appDelegate.
Ensure you add the setFetchLimit: after any predicates you wish to use.