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
Related
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.
I read tutorial here
http://adeem.me/blog/2009/05/19/iphone-programming-tutorial-part-1-uitableview-using-nsarray/
which shows how to fill a UITableView at initialization. I can't find tut to do so after initialization (for example when User has clicked on a button).
Any suggestion ?
You would just update the data source and reload the table view.
Following that tutorial, you would do it like so:
- (IBAction)myButtonPressed:(id)sender
{
self.arrayData = [[NSArray alloc] initWithObjects:#"iPhone", #"iPod", #"MacBook", #"MacBook Pro", #"iMac"];
[self.tblSimpleTable reloadData]
}
This will tell the UITableView to reload the data source and adjust the amount of sections, rows etc.
Note that you might prefer to use a NSMutableArray instead.
[self.mutableArrayData addObject:#"iMac"];
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.
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)
I am writing a program, and one part of my program has a UItableView in which I set cell contents manually by using the following...
cell.textLabel.text = #"CELL CONTENTS HERE!";
How can I copy a string displayed in a particular TableView Cell into another NSString?
Try something like this:
NSString *anotherString = [NSString stringWithString:cell.textLabel.text];
Keep your #"CELL CONTENTS HERE!" string as a #property of your view controller. Then set the cell's text property to it:
cell.textLabel.text = cellContentsHereProperty;
inside the table view delegate method -tableView:cellForRowAtIndexPath:. You want to do this because you can only access cell.textLabel.text inside this method, or by calling the delegate method to retrieve the cell, which is awkward.
As a general concept, you want your view controller ("control") to keep the string value ("model") separate from how it is displayed ("view"). Keeping things compartmentalized lets you retrieve and change the data without worrying about how it is displayed.
This separation of responsibilities is called the MVC or Model-View-Control design pattern, which Apple subscribes to for iPhone application design.