I am trying to work out how I can display two data cells in a UITableView Row.
All my data is stored in an SQLite table.
At the moment I run a query to extract a list of countries into an array "arrayOfCharacters" and also create another array "objectsForCharacters".
The arrayOfCharacters is to create an A - Z index for use in table sections and the objectsForCharacters hold the names of countries.
In cellForRowAtIndexPath I display the name of the country but I would like to display the capital city at the same time. The fields in the table that hold the data are called "countryName and CountryCapital. How can I display the countryCapital.
I have been playing around with this for days without any success, can any help me out.
Well, you are using the stock TableCell in your Table, which just has one textfield. So you could just create a string that has both values and set that one textfield to that value.
You have, which adds just one string value.
Code:
// Set up the cell
cell.textLabel.text = [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
Using NSString's stringWithFormat method, you can concatenate two values into one string like
Code:
// Set up the cell
cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row], <<<<put in call to get your other string;
The other option is always to create your own TableCellView, add two UITextFields and set one to one value and the other to the other.
If all you want is just a string with those values, I would go the first route. But if you want it to look different, or say one text value above the other, or some other stuff, then a custom tablecell view is the way to go.
I think my problem is I am not sue how to make the call to get the other string. the code below is how I am running my query to get the data. How would you go about getting the name of the "countryCapital" so it could be displayed.
You would just call sqlite3_column_text(statement, 1) to get your countryCapital. This will get you the value from your second column returned by your select statement.
__________________ Recall It!Tag your notes. Tag your photos. Tag your thoughts. Tag your life.
cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row], <<<<put in call to get your other string;
How would I call the content of "countryCapital"
I am sorry to be a pain in the "lets just say neck" and I do appreciate your time.
__________________
Many thanks, keep safe and well.
Or however you want it formatted... this example would be formatting it as something like "Japan (Tokyo)". Seems like adding two objects to your array for each entry is just more confusing. Another thing I'd consider is creating some sort of custom class or struct to track the contents of each record, and add the record into your array.
__________________ Recall It!Tag your notes. Tag your photos. Tag your thoughts. Tag your life.
What I am trying to do is to use the second index of the array to display the countryFlag. I have been trying to do this for days without success. And anyone provide some help.
__________________
Many thanks, keep safe and well.
Well, you are using the stock TableCell in your Table, which just has one textfield. So you could just create a string that has both values and set that one textfield to that value.
You have, which adds just one string value.
Code:
// Set up the cell
cell.textLabel.text = [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
Using NSString's stringWithFormat method, you can concatenate two values into one string like
Code:
// Set up the cell
cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row], <<<<put in call to get your other string;
The other option is always to create your own TableCellView, add two UITextFields and set one to one value and the other to the other.
If all you want is just a string with those values, I would go the first route. But if you want it to look different, or say one text value above the other, or some other stuff, then a custom tablecell view is the way to go.
Mark
I think the correct and simplest way of displaying two texts on a table view cell, is to use the UITableViewCellStyleSubtitle style and then set the textLabel and detailTextLabel.
The second text from the array is the name of the country and I want to use it to display the country flag. I have all the flag images in the App which are named after the country, example: if the country is "Romania" the the content of the countryFlag would be "romania".
I then want to display the flag "romania" in the table row to the left of the country name. The code that I am playing around with is below, somewhat of a mess at the moment:
Code:
// Set up the cell
cell.textLabel.text = [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
[[cell textLabel] setTextColor: [UIColor colorWithRed:139.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:1.0]];
UIImage *image = [UIImage imageNamed:[[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]];
cell.imageView.image = countryFlag;
What I am trying to do is somehow use the following code to display the image, the problem is I am completely lost.
Abkhazia Abkhazia
Afghanistan Afghanistan
Albania Albania
Algeria Algeria
American Samoa American Samoa
What it should display is:
Abkhazia
Afghanistan
Albania
Algeria
American Samoa
and so on.
What I am trying to do is use the content of the second name as a variable for each row to display the country flag as an image. As I was saying I have all the country flag images in the App and they are all .gif images.
I have tried all ways to do this without success which is partly down to my lack of experience with Objective-C.
__________________
Many thanks, keep safe and well.
Please add the entire project (or a compilable section, containing the problem), I intend to build it and debug it, its much faster than just looking at the code.