Push from TableView to another TableView gets Black Screen - iphone

I select a row from a TableView which gets informations from a Webservice. Everything is loaded: A search, then we get results and then choose one.
But after choosing one, I can set the data to the other view and make another web service to Work.. I'm okay with that.
The problem is to show the new table containing the results of the new web service..
I get this after choosing a row from the last table View:
2012-04-30 13:54:29.687 +%¨*%¨%¨*[6759:f803] JSON(
"Name Gerald",
"",
4,
FR,
""
)
I made this with this:
NSString *nom = [olo objectForKey:#"name"];
NSString *hd = [olo objectForKey:#"24_7"];
NSString *passenger = [olo objectForKey:#"passengers"];
NSString *country = [olo objectForKey:#"country"];
NSString *special = [olo objectForKey:#"special_trip"];
_jsonOlo = [[NSMutableArray alloc] initWithObjects:nom, hd, passenger, country, special, nil];
But when I set the table I get a black screen :
1st:
http://tinypic.com/r/2uzpc20/6
2:
http://tinypic.com/r/287qeeq/6
I have the same code as the last tableView which sends to the results but I get Black screen.

If the two tableviews are different and you are not simply changing the datasource of the same table then your view might be loading before you have got all the data from web service .I don't know, which framework you are using for json parsing but there should be a delegate which signifies the end of getting results from web service . Parse the data there and then send it to the tableview in viewDiDLoad method.

You might not have connected the tableview properly in your XIB or you might not have added subview to main view or u must have allocated it when the webservice has finished retrieving data but u might have touched it before.
You can do one thing: make the cell selection disable till u are ready with all the data.

Related

App crashes when adding names to UIPickerView

When I click a button, a UIAlertView prompts the user to type a name. This name is then created as a new 'Customer' object and inserted into a mutable array.
There is a separate mutable array called 'CustListByName', which stores a list of all names.
The problem im having is that when adding a second or third name, the app crashes. Sometimes it happens on the second try, other times on the third try. There is no information given in the debugger except for (lldb). The program reports EXC_BAD_ACCESS and then it dumps me to a screen with a bunch of assembly code.
The crash is happening in these lines of code:
Essentially, it clears the array of names and then repopulates it based upon the object array. I've studied in step by step with a breakpoint but everything seems correct up until the point of crash. It is also confusing why this happens on the second or third try, never the first.
[custListByName removeAllObjects];
for (Customer *object in custListByObject) {
[custListByName addObject:object->name];
}
Here is the code where a customer is created and inserted everytime the new customer button is clicked:
Customer *tempCust = [[Customer alloc] init];
tempCust->name =[[alertView textFieldAtIndex:0] text];
[custListByObject addObject:tempCust];
[tempCust release];
I would really appreciate help with this, thanks!
What I suspect is happening is that the UIPickerView is attempting to load a row using information from your customer array after you have already cleared it, and before you repopulate it. This would cause a bad access error.
What you may consider doing instead, is keeping two arrays, an NSMutableArray for loading the customers, and an NSArray as the actual data source for the UIPickerView. Then right before you reload the UIPickerView, you say:
dataSourceArray = [loadingArray copy];
[pickView reloadAllComponents];
Hopefully this helps.
Edit:
Here's what your updated code would look like if your loading array was called loadingCustListByName:
[loadingCustListByName removeAllObjects];
for (Customer *object in custListByObject) {
[loadingCustListByName addObject:object->name];
}
custListByName = [loadingCustListByName copy];
[pickView reloadAllComponents];
Doing this will ensure that the UIPickerView's datasource array always matches up with the number of rows it thinks it has.

Core data edit function

I already have a tableView with data in it. IF you tap a cell/row it pushes to an edit type of view. Is there anyway to edit core data's data other than: By edit, i mean i already have data inserted into my context. I have loaded my data into my view, the user can change the existing data, and re save it.
.h
//Below is the entity/entity's class name 'Amm'
Amm *amm;
.m
-(IBAction)save
{
[self.amm setValue:self.nameField.text forKey:#"name"];
[self.amm setValue:self.nicknameField.text forKey:#"nickname"];
[self.navigationController popViewControllerAnimated:YES];
NSError *error;
if (![self.managedObjectContext save:&error]) {
//Handle Error
}
}
I want this code to work, however the design pattern of my app isnt allowing this code to work for me as it does in other parts of my app. Thank you very much for any and all help!
I assume from what you've said you have:
A table view listing your managed objects
A view where you can edit the values of a managed object
A save button bound to the save method
What's the actual issue? I'm assuming when you tap save that:
The values in self.nameField.text isn't setting self.amm.name
The values in self.nicknameField.text isn't setting self.amm.nickname
Is that right? If so perhaps try the following code to set the managed object values:
self.amm.name = self.nameField.text
self.amm.nickname = self.nicknameField.text
If that's not the issue and you are actually setting the managed object values properly, is it that you just need to refresh the table-view? Perhaps use some NSLog commands to log every step of the applications progress.

iphone sql - data corrupted/ missing when reading

I'm using SQL to store data in my application. I read data in the app delegate and store it in an array like so.
(First I read from the database and store in aFlashcardSet and then this)
// Add the flashcardSet to the main Array
[mainSetsArray addObject:aFlashcardSet];
In my next view I then copy the data from the app delegate.
flashcardsAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
self.setsArray = delegate.mainSetsArray;
Then I pass one object from the set to the final view.
cardDetailViewController.thisCardSet = [setsArray objectAtIndex:row];
The problem is when I read the data in the final view and use to set UI elements the app crashes, the code works fine with data hard coded during the second phase and the database data is shown fine during the second phase (to populate a table view). I've tried outputting the data at all stages and it is all correct until the final view where it either crashes or shows incorrect values (file names or random letters rather than the actual text).
I have also tried to read the database data inside the final view and set it to thisCardSet but it still suffers the same problem.
Any ideas?
Thanks.
The problem was inside one of my custom classes I wasn't using self, so I was writing.
aString = string;
Rather than -
self.aString = string;
So I was losing data down the line, feel really stupid but hope it help's someone else =].

Cocoa Touch: are dynamically XML-defined views possible?

first post. Been an iPhone developer intern for about five weeks now. I've read a lot of introductory Apress material, but please take it easy if I make some vocabulary violations. So far I've been able to find answers by searching and lurking. However I now have a task for which I can find little relevant information.
My iPhone application currently uses a rigid view hierarchy for selection of items. The MainViewController links to (err, Subviews?) a TableView for selecting any from a list of factories. Selecting a factory then loads a TableView for various statistics about that factory. The data to populate these tables loads from a remote JSON server by http.
I would like to have an XML definition of the view hierarchy on the remote server from which the application dynamically constructs the view structure. In this way the view structure is not hard-coded into the client (the iPhone ViewControllers/nibs) and offers more flexibility for reorganizing the content server-side.
Is this possible, and has anybody accomplished this? Most relevant answer was Dynamic UI in iphone, however upon reading I feel Apple's guide to Serializing/Archiving departs quickly from what I am trying to do. Can somebody explain its relevance or point to another resource?
Yes, it is entirely possible, and I (as well as others) have done something similar. Essentially, you will have to write a couple classes:
One is a Controller class to parse the XML to get the content you need upon download into a format you can use in a Model class. There are a number of OSS libraries out there, but don't use Cocoa's XML classes on the iPhone because they are just too slow when parsing. Be sure to double-check the license that comes with the OSS library so that you don't run afoul of GPL and the like.
The second class you'll need is one that will translate your model into a view hierarchy and place it on screen on the fly as the user moves through the content. This is to implement as individual steps, but the challenge is managing the content placement workflow.
The content noted in your question does depart a bit from the core task at hand but it can still be relevant to your interests. At the very least it may give you an idea on how to approach certain aspects of your project.
Here's a follow-up. I have accomplished what I wanted to do.
I have a ListViewController class and a Repository model/object. To parse XML, I used XPathQuery, Matt Gallagher's adaptation of libxml2 for Cocoa (http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html).
The ListViewController tracks the current XML path. When a cell in the table view is selected, the corresponding path is concatenated to the existing path. The ListViewController creates and pushes another instance of itself and PerformXMLPathQuery() returns an array to populate the table view cells. The Repository holds an NSMutableData object and an NSString with current path. Both are required for XPath Query:
NSArray *PerformXMLXPathQuery(NSData *document, NSString *query);
PerformXMLPathQuery does a lot of back work for you. This is how I used it to get what I wanted from the XML:
-(NSArray*)getListFromRepositoryWithPath:(NSString *)path {
// Get the nodes referred to by the path
NSArray *nodes = PerformXMLXPathQuery(repository.data, path);
// Build an array with the node names
NSMutableArray* sublist = [[NSMutableArray alloc] init];
for (NSDictionary* node in nodes) {
for (id key in node) {
if ([key isEqualToString:#"nodeChildArray"]) {
NSArray* subNodes = [node objectForKey:#"nodeChildArray"];
for (NSDictionary* subNode in subNodes) {
for (id subKey in node) {
if ([subKey isEqualToString:#"nodeName"]) {
[sublist addObject:[subNode objectForKey:subKey]];
}
}
}
}
}
// Ignore duplicate entries in the data
if ([sublist count] > 0) {
return [NSArray arrayWithArray:sublist];
}
}
return [NSArray arrayWithArray:sublist];
}
When a row is selected, I used didSelectRowAtIndexPath to prepare the next path and view controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *nextXpathQueryString = [self.xpathQueryString copy];
// Build the path string for the next view's XML path query
if ([[nextXpathQueryString lastPathComponent] isEqualToString:#"*"]) {
nextXpathQueryString = [nextXpathQueryString stringByDeletingLastPathComponent];
nextXpathQueryString = [nextXpathQueryString stringByAppendingPathComponent:#ROOTNAME];
}
nextXpathQueryString = [nextXpathQueryString stringByAppendingPathComponent:[repository.currentListToDisplay objectAtIndex:indexPath.row]];
// Navigation logic. Create and push another view controller.
ListViewController *detail = [[ListViewController alloc] init];
// Populate the new ViewController
[detail setRepository:repository];
[detail setTitle:nextXpathQueryString];
[detail setXpathQueryString:nextXpathQueryString];
[nextXpathQueryString release];
UIBarButtonItem *doneButton = [[self navigationItem] rightBarButtonItem];
[[detail navigationItem] setRightBarButtonItem:doneButton animated:YES];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detail animated:YES];
[detail release];
}
The cool thing is each instance of ListViewController keeps its own path string and content array. No fooling around with nested tree objects or pointers.
Essentially I have a flexible XML tree browser for the iPhone. Thanks Stack Overflow.

how do i authenticate the user and load a table view on success?

i'm new to iphone dev.. i was trying to create an application which will authenticate the user and download some data from de url(.php) via xml parsing into the table view. i have figured how to parse and populate the table view but stuck up with user authentication... ie- extracting textfield data and appending it to the URL on submit. n loading table view on success... could anyone please help me out..
I’m going to separate this answer into two parts: one for appending the user name onto the URL and another for populating the table view.
Appending the User Name Onto the URL
Right now, you probably have a string for the URL (we’ll call it URLString) and a text field for the username (we’ll call it usernameTextField). Here is how you would append the contents of the text field to the URL string.
NSString *URLString = #"http://your.domain.goes.here/something?user=";
NSString *userName = [ usernameTextField text ];
NSString *newURLString = [ URLString stringByAppendingString:userName ];
NSURL *URLToLoad = [ NSURL URLWithString:newURLString ];
That gives you an NSURL to use in fetching the data.
Populating the Table View
Here, you want to have a function that loads the data from the URL. Where you currently parse the XML, add in some error-checking that checks to see if the page is valid. If so, you can call
[ tableView reloadData ];
to reload the table view. In your table view data source’s implementation of the numberOfSectionsInTableView:, numberOfRowsInSection:, cellForRowAtIndexPath:, and other methods, check to see if valid data has been received and, if not, either display no sections and no rows or display a cell with a message to the user to log in.
[myTextField text];
this line will extract data from your text field. for login you can use NSMutableURLRequest ot, for rxample, ASIHTTPRequest(this is third-party library) to login. then you can show your tableView in request's delegate method