Hey guys, i have a simple app just a load of images in one image view. Each is just included in a plist file and called when a cell is selected in popover window. All i want is a button with an action to get next item in plist and display in the image window. this sounds easy but i cant figure out the code to grab next item in plist? can anyone help cheers
I'm not sure what the structure of your property list is, but I'm just going to guess that it's just a property list with one string containing the image name per row. The easiest way to manage this is to just dump the plist file into an array like this:
// Load the data
NSString *pathToFile = [[NSBundle mainBundle] pathForResource:someArrayNameString ofType:#"plist"];
self.someArrayYouCreated = [NSArray arrayWithContentsOfFile:pathToFile];
then you can access the data in the array like this:
// load it into some string you created
nextImageNameString = [someArrayYouCreated objectAtIndex:nextImageNumberHere];
and then you can just use that string name as the next image to load. So basically,
Dump plist into an array
Use objectAtIndex to access the images (remember, arrays start at index 0)
Related
I'm loading a json file from my server which have several fields like id,category,value,price.i tried SBJSON library files. If i'm trying to display single content in a cell i'm using the following code
cell.textLabel.text=[[mutarray objectAtIndex:indexPath.row] valueForKey: #"id"];
but if i need to display all the field like id,category,value in each cell.i'm not aware of that.Kindly guide me..
here mutarray is my NSMutableArray which contains all elements of my json file..
You will need to put custom cells. Please check the link below and tell me if any doubts.
Putting Custom Cells in Table View
i done that using following code
cell.textlabel.text=[[NSString stringWithFormat:#"%#",[[mutarray objectAtIndex:indexPath.row] valueForKey: #"id"]];
The issue is i forgot to convert the JSON Object into NSSTring
I'm trying to initialize a tableview with an image, name and surname of each user that I have stored in a NSMutableArray.
In this mutablearray I save a class that I created to store users data and its schema is as follows:
ResultSearchController{
NSInteger *userID;
NSString *userName;
NSString *userSurname;
NSString *userThumb;
}
I have read the documentation of TableView but I still have doubts and problems to display the data in TableView (seems rather complicated to use such objects). Could you help me to get started with this?
Thanks!!
I guess you have a Custom UITableViewCell for that.
Simply use in cellForRowAtIndexPath delegate of UITableView (to set the image):-
yourCustomCellObject.yourImageViewINCustCell.image=[UIImage imageNamed:[(yourClassToStoreData *)[yourNSMutableArray objectAtIndex:indexPath.row] userThumb]];
Similarly you can do in the same manner to set other control elements.
It's just an example of how you can do.I am assuming you have stored the data over some class objects and adding it to an NSMtableArray.
Is it possible to display a sqlite values in a textview?I have made it in a tableviewcontroller,but i am not able to display the same in a textview. appdelegate.biblearray is the array that holds the sqldata.I have the same qustion in another forom .please look at this link for that question [here is the link]: How to show sqlite datas in a textview?
Please help me to do this.
Thanks.
Instead of doing
bible *jesus = (bible *)[appDelegate.biblearray objectAtIndex:indexPath.row];
use string variable or the type of value that biblearray contains
NSString *str = [appDelegate.biblearray objectAtIndex:indexPath.row];
For only displaying in textview, you dont need to use class object jesus.
I have a table view which goes down a few levels. On the last level is a table view with information(which is taken from a plist) about the item that was selected.
I want to click on one of the cells to launch a new view, Mapview to show the co ordinates which are stored in the plist.
I can add the view and get the basics of the map view working but I'm having trouble accessing the co ordinates which are stored in the plist.
I've looked for guidance on other websites and they access the plist from the viewdidload in the mapviewcontroller and do objectforkey to get the co ordinates, but my coordinates are a few levels down in the plist and since i can't do indexforpath in viewdidload is there an alternative way of doing it?
The way I would do this, is when you select a row in a table view, select the objectAtIndexPath, and pass it to the next view (perhaps as an object called selectedItem)
then when you are in view did load, you could do something like this:
-(void)viewDidLoad{
...
CLLocationCoordinate2d coordinate=CLLocationCoordinate2dMake([[self.selectedItem latitude] doubleValue],[[self.selectedItem longitude] doubleValue]);
...
}
without seeing your plist structure, and also your ViewController Hierarchy, it is quite difficult to see if this approach would help.
edit:
having looked at your xml file, you can drill into your plist like this:
NSArray *rows=[[NSDictionary dictionaryWithContentsOfURL:<url>] objectForKey:#"Rows"];
NSArray *children=[[rows objectAtIndex:< >] objectForKey:#"Children"];
NSDictionary *item=[children objectAtIndex:< >];
CLLocationCoordinate2d coordinate=CLLocationCoordinate2dMake([[item objectForKey:#"Latitude"] doubleValue],[[item objectForKey:#"Longitude"] doubleValue]);
I have a mapView and tableView, with each annotation in the mapView corresponding with a cell in the table. What I want to do is select the appropriate cell anytime an annotation is selected on the map.
As of right now, im creating an NSDictionary when the cells are created, which maps the row number to the annotationID. This works, but the problem is that the dictionary isnt completely populated until all the cells have been created, and all the cells arent created until youve scrolled all the way through the table. Thus, when the app starts for the first time, only the 4 annotations originally visible can be selected from the mapView.
So what im looking for is either a method to automatically populate my dictionary, or a better way of accomplishing what i need to do. Thanks a lot!
Well, first thoughts are that instead of populating the NSDictionary during scrolling, just populate it during viewDidLoad ..I do something similar where I populate all of my data into an NSDictionary and then use that to initialize/update the UI on the cells during scrolling for re-usable cells.
Also, by putting your data into an array of some kind, you can also map it to the cells. Just remember that arrays start at 0, so position in table = indexOfYourArray + 1
Simple example of loading an array stored in a plist into an NSArray in viewDidLoad
// Load the data
NSString *pathToFile = [[NSBundle mainBundle] pathForResource:someArrayNameString ofType:#"plist"];
self.someArrayYouCreated = [NSArray arrayWithContentsOfFile:pathToFile];
Now that you just dumped a whole bunch of data into that array, you can populate it during scrolling in cellForRowAtIndexPath
NSDictionary *dataItem = [someArrayYouCreated objectAtIndex:indexPath.row];
UILabel *label;
label = (UILabel *)[cell viewWithTag:1];
label.textColor = [UIColor colorWithRed:(58/255.f) green:(58/255.f) blue:(58/255.f) alpha:1.0];
label.text = [dataItem objectForKey:#"PersonName"];
With this example, you are just populating the cells from an array that you created in viewDidLoad and therefore all of your data is ready to use almost right away. If you have a ton of data, you could also throw up a progress circle to delay for a second until the array is finished loading.
Again, I don't quite understand how you are storing your data (since you have not said anything about that) so I can only speculate that this will work for you. Until you provide more detail, this is the best I can do.