text not showing in table view cell unless cell touched - ios

I have table view set up in the traditional Master/Detail way in an iPhone app. When I click save on the detail screen (after adding the information I want), it switches back to the master list, however, the text that's supposed to appear in the cell in the Master list doesn't appear until I touch the cell with my finger, however, if I touch the cell with my finger it obviously segues to the detail screen and then I have to click "back" to get to the Master list where the cell now has the text that it's supposed to. Interestingly, the table view image is appearing immediately upon save - I don't have to touch the cell to make the image appear in the same way I have to make the text appear.
Clicking the "save" button in the detail screen runs this code. The mnemonicField.text gets saved to the currentTopic and I later set it to be the text that appears in the cell
- (IBAction)save:(id)sender {
[self.currentTopic setTopic:topicField.text];
[self.currentTopic setMnemonic:mnemonicField.text]; //this should appear in cell on master
[self.currentTopic setMood: self.mood];
[self.delegate AddTopicViewControllerDidSave];
}
The Master table view controller is the delegate referred to in the above method. Here is that method.
-(void)AddTopicViewControllerDidSave{
NSError *error = nil;
NSLog(#"saving topick");
NSManagedObjectContext *context = self.managedObjectContext;
if (![context save:&error]){
NSLog(#"Error: %#", error);
}
[self.navigationController popToRootViewControllerAnimated:YES];
}
In cellForRowAtIndexPath, I call another method to setup the cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TopicCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier forIndexPath:indexPath];
[self configureCell:cell atIndexPath:indexPath];//sets up cell, see below
return cell;
}
Here's configureCell:atIndexPath which sets up the cell. Again, note that both the image and the textLabel.text are set in this method but that I have to touch the cell with my finger to actually make the text appear
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
// Configure the cell...
Topic *topic = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = topic.mnemonic;
NSLog(#"jokemood in configure cell %#", joke.mood);
UIImage *funnyimage = [UIImage imageNamed: #"nslaugh.png"];
UIImage *badimage = [UIImage imageNamed: #"nsbad.png"];
UIImage *crapimage = [UIImage imageNamed: #"nscrap.png"];
UIImage *mehimage = [UIImage imageNamed: #"nsmeh.png"];
UIImage *smileimage = [UIImage imageNamed: #"nssmile.png"];
switch ([topic.mood intValue]) {
case 0:
// do something
NSLog(#" topic table 0");
cell.imageView.image = crapimage ;
break;
case 1:
After some experimentation, I determined that the problem is this line cell.textLabel.text = topic.mnemonic; in the above function. If I take that line out, then the title shows in the cell in the master list immediately upon saving in the detail screen. However, if I take that line out, then when i start the application, the title is not getting assigned when the data's pulled from core data. So, either way there's a problem. If this line cell.textLabel.text = topic.mnemonic; is left in the above function, then I have to touch the cell in the master list (after saving in the detail) for the text to appear, but if I take that line out then the textLabel.text is not getting assigned when the application pulls from core data. Neither option is acceptable.
Do you know why this might be happening?
For the sake of completion here's prepareForSegue in the master view controller where I setup the currentTopic on the destination view controller based on the topic in the master view controller
if ([[segue identifier] isEqualToString:#"AddJoke"]){
MMAddTopicViewController *ajvc = (MMAddTopicViewController *)[segue destinationViewController];
ajvc.delegate = self;
ajvc.mood = nil;
Topic *newTopic = (Topic *)[NSEntityDescription insertNewObjectForEntityForName:#"Topic" inManagedObjectContext: [self managedObjectContext]];
NSMutableSet* relationship = [self.rootObject mutableSetValueForKey:#"subItems"];
NSManagedObject *lastObject = [self.fetchedResultsController.fetchedObjects lastObject];
double lastObjectDisplayOrder = [[lastObject valueForKey:#"displayOrder"] doubleValue];
[newTopic setValue:[NSNumber numberWithDouble:lastObjectDisplayOrder + 1.0] forKey:#"displayOrder"];
[relationship addObject:newJoke];
ajvc.currentTopic = newTopic; ///currentTopic in destination view controller is set to topic from master view controller

I added [self.tableView reloadData]; in the save method in the master view controller, which is called from the detail controller (master serves as the detail's delegate). The Lynda.com tutorial I copied it from didn't have to use self.tableView reloadData, not sure why my code did.
-(void)AddTopicViewControllerDidSave{
NSError *error = nil;
NSLog(#"saving cock");
NSManagedObjectContext *context = self.managedObjectContext;
if (![context save:&error]){
NSLog(#"Error: %#", error);
}
[self.navigationController popToRootViewControllerAnimated:YES];
[self.tableView reloadData];
}

Related

Get UICollectionViewCell from indexPath when UIBarButtonItem is tapped

I have created a View Controller with a Navigation bar and UiCollectionView. UI Collection View contains custom UICollectionViewCell. Navigation bar contains two UIBarButton items, one is on the left corner - prepared segue to previous page and other item is on the right corner - arranged to delete cell(s) in the UI CollectionView as show in the picture below:
Main Screen
Now I want to remove the selected UICollectionViewCell when UIBarButtonItem in the right corner, is tapped.
This how my cellForItemAtIndexPath method look like:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath{
self.GlobalIndexPath = indexPath;
MessagesCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"messagesCell" forIndexPath:indexPath];
cell.MessageHeading.text = [self.Message_Heading objectAtIndex:indexPath.row];
cell.MessageSubject.text = [self.Message_Subject objectAtIndex:indexPath.row];
cell.MessageContent.text = [self.Message_Details objectAtIndex:indexPath.row];
[cell.Checkbox setHidden:YES];
[cell.Checkbox setChecked:NO];
}
I have tried a solution like Declaring Indexpath as global variable and use it in the button event as below:
#property (strong,nonatomic) NSIndexPath *GlobalIndexPath;
some other code .......
//When Bin Icon(UIBarButtonItem) Clicked
- (IBAction)DeleteMessages:(id)sender {
[self.view makeToast:#"You clicked delete button !"];
NSIndexPath *indexPath = [self.MessageCollectionView.indexPathsForVisibleItems objectAtIndex:0] ;
BOOL created = YES;
// how to get desired selected cell here to delete
MessagesCollectionViewCell *cell = [self.MessageCollectionView cellForItemAtIndexPath:self.GlobalIndexPath];
if([cell.Checkbox isHidden])
{
[cell setHidden:YES];
}
else{
[cell.Checkbox setChecked:NO];
[cell.Checkbox setHidden:YES];
}
}
It's not worked.
For showing the UICollectionViewCell selected as checked, i'm using #Chris Chris Vasselli's solution
Please help me with this. Thanks in Advance.
There are a few steps. First, determine the selected indexPath, but don't assume there is a selection when the method is run....
// in your button method
NSArray *selection = [self.MessageCollectionView indexPathsForSelectedItems];
if (selection.count) {
NSIndexPath *indexPath = selection[0];
[self removeItemAtIndexPath:indexPath];
}
There are two more steps to remove items from a collection view: remove them from your datasource, and tell the view it has changed.
- (void)removeItemAtIndexPath:(NSIndexPath *)indexPath {
// if your arrays are mutable...
[self.Message_Heading removeObjectAtIndex:indexPath.row];
// OR, if the arrays are immutable
NSMutableArray *tempMsgHeading = [self.Message_Heading mutableCopy];
[tempMsgHeading removeObjectAtIndex:indexPath.row];
self.Message_Heading = tempMsgHeading;
// ...
Do one or the other above for each datasource array. The last step is to inform the collection view that the datasource has changed, and it must update itself. There are a few ways to do this. The simplest is:
// ...
[self.MessageCollectionView reloadData];
OR, a little more elegantly:
[self.MessageCollectionView deleteItemsAtIndexPaths:#[indexPath]];
} // end of removeItemAtIndexPath

How come my array loads but my tableView will crash with index beyond bounds for empty array?

This is my error:
-[__NSArrayM objectAtIndex:]: index 12 beyond bounds for empty array
I know this error means I'm trying to access an "empty array".
This error only happens in viewX when it is popped back from viewY. When you press 'back button' on navigation bar in viewY and scroll the tableView immediately, it will crash and cause this error. I am using the RETableViewManager to load my tableView.
In viewX's viewDidLoad:
[[RACSignal combineLatest:#[RACObserve(self, record), RACObserve(self, restaurant)]] subscribeNext:^(id x) {
[self setupItems];
}];
in setupItems:
RecordManager *recordManager = [[EZRecordManager alloc] initWithRecord:self.record restaurant:self.restaurant sender:self.navigationController];
self.items = [recordManager items];
self.section = [RETableViewSection section];
[self.items each:^(id data) {
if ([data isKindOfClass:[NSString class]]) {
self.navigationItem.title = (NSString *)data;
} else {
[self registerItem:[data class]];
[self.section addItem:data];
}
}];
[self.manager addSection:self.section];
[self.tableView reloadData];
I NSLogged my array 'self.items'. and this is what logs according to the method:
viewDidAppear - (
"\U5df2\U8a02\U4f4d\Uff0c\U5c1a\U672a\U7528\U9910",
"<REReservationHeaderItem: 0x14015b0b0>",
"<REAttributedStrItem: 0x14015b1b0>",
"<REAttributedStrWithNextItem: 0x140191a70>",
"<REAttributedStrItem: 0x140193f60>",
"<RESpacerItem: 0x140194870>",
"<REAttributedStrWithNextItem: 0x14019ce10>",
"<REAttributedStrItem: 0x140199230>",
"<RESpacerItem: 0x1401a04e0>",
"<REActionItem: 0x14019e490>",
)
The NSLog logs the same array in setupItems so I know the array is still there because self.item is saved as a property:
#property (nonatomic, strong) NSArray *items;
So this algorithm works as expected when I'm loading viewX for the first time, but as soon as I go into another view(viewY) and press the 'back button' on viewY to pop to viewX and then immediately scroll, it crashes with the above error. If I wait for a second (maybe even half a second), viewX will work properly and have no issue. I know this is minor but my PM is stressing that this shouldn't happen. How can I solve this problem?
The method the error occurs in (part of the RETableViewManager library):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
RETableViewItem *item = [section.items objectAtIndex:indexPath.row];
UITableViewCellStyle cellStyle = UITableViewCellStyleDefault;
if ([item isKindOfClass:[RETableViewItem class]])
cellStyle = ((RETableViewItem *)item).style;
NSString *cellIdentifier = [NSString stringWithFormat:#"RETableViewManager_%#_%li", [item class], (long) cellStyle];
Class cellClass = [self classForCellAtIndexPath:indexPath];
if (self.registeredXIBs[NSStringFromClass(cellClass)]) {
cellIdentifier = self.registeredXIBs[NSStringFromClass(cellClass)];
}
if ([item respondsToSelector:#selector(cellIdentifier)] && item.cellIdentifier) {
cellIdentifier = item.cellIdentifier;
}
RETableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
void (^loadCell)(RETableViewCell *cell) = ^(RETableViewCell *cell) {
cell.tableViewManager = self;
// RETableViewManagerDelegate
//
if ([self.delegate conformsToProtocol:#protocol(RETableViewManagerDelegate)] && [self.delegate respondsToSelector:#selector(tableView:willLoadCell:forRowAtIndexPath:)])
[self.delegate tableView:tableView willLoadCell:cell forRowAtIndexPath:indexPath];
[cell cellDidLoad];
// RETableViewManagerDelegate
//
if ([self.delegate conformsToProtocol:#protocol(RETableViewManagerDelegate)] && [self.delegate respondsToSelector:#selector(tableView:didLoadCell:forRowAtIndexPath:)])
[self.delegate tableView:tableView didLoadCell:cell forRowAtIndexPath:indexPath];
};
if (cell == nil) {
cell = [[cellClass alloc] initWithStyle:cellStyle reuseIdentifier:cellIdentifier];
loadCell(cell);
}
if ([cell isKindOfClass:[RETableViewCell class]] && [cell respondsToSelector:#selector(loaded)] && !cell.loaded) {
loadCell(cell);
}
cell.rowIndex = indexPath.row;
cell.sectionIndex = indexPath.section;
cell.parentTableView = tableView;
cell.section = section;
cell.item = item;
cell.detailTextLabel.text = nil;
if ([item isKindOfClass:[RETableViewItem class]])
cell.detailTextLabel.text = ((RETableViewItem *)item).detailLabelText;
[cell cellWillAppear];
return cell;
}
Usually when "waiting a little fixes the problem", it's because you have an async problem.
Something to check first :
Make sure your reload code is called when you move back. Maybe your tableview didn't get emptied, but the array did. Moving back would let you scroll the old content (still loaded) but the delegate methods won't be able to create new cells because the array is now empty.
If you wait, your async method does it's job and the array is now full again, which makes everything work fine.
Possible solution :
Empty then reload the tableview in viewWillAppear. This will cause a visual flash of the tableview going empty and then full again. It will also scroll you to the first element. That being said, it's really easy and fast, and with a spinner it will appear much smoother.
Other possible solution :
Keep the data loaded after leaving the page, so when you come back it's still there. You can use anything that will keep the data loaded while in the app. It could be a singleton class that stays instantiated, or save in a database and reload from it (it's much faster than straight up loading from the internet), or anything that you can think of.

How can I have a Table Cell to perform two different segues but with conditions?

I am new to iOS Development so please forgive me for asking silly questions or performing silly actions.
So now, here's the problem. I am developing an app, I have a tab bar controller as the initial, called [Initial Tab View]. One of the tab is a table view that displaying all the items, lets call this [Item View]. Once the user tap on the cell, it will push to another view and show the details, the [Detail View]. Another tab is also a table view but with static cells, [Static View], which I use it to select an item and return.
For a clearer picture: If I access the [Item View] from the initial tab view, just simply follow [Initial Tab View]->[Item View]->[Detail View]. However, if I access the [Static View] first and then go to the [Item View], the procedure will be like [Initial Tab View]->[Static View]->[Item View]->[Static View].
I have no idea how to implement the second one (with the [Static View] one) in [Item View], can anyone help? Or there is another better approach? Many thanks.
// Code from [Item View]
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = #"CustomShopCell";
ShopCustomTableCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[ShopCustomTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:identifier];
}
if (searchResult != nil) {
//cell.textLabel.text = [searchResult objectAtIndex:indexPath.row];
Shop *shop = searchResult[indexPath.row];
if ([shop.shopNameChi length] == 0) {
cell.lblName.text = shop.shopName;
} else {
cell.lblName.text = [NSString stringWithFormat:#"%# | %#", shop.shopName, shop.shopNameChi];
}
cell.lblLocation.text = shop.unit;
cell.imgImage.contentMode = UIViewContentModeScaleAspectFit;
cell.imgImage.image = [UIImage imageWithData:shop.imageData];
} else {
//cell.textLabel.text = [list objectAtIndex:indexPath.row];
Shop *shop = shopList[indexPath.row];
if ([shop.shopNameChi length] == 0) {
cell.lblName.text = shop.shopName;
} else {
cell.lblName.text = [NSString stringWithFormat:#"%# | %#", shop.shopName, shop.shopNameChi];
}
cell.lblLocation.text = shop.unit;
cell.imgImage.contentMode = UIViewContentModeScaleAspectFit;
cell.imgImage.image = [UIImage imageWithData:shop.imageData];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(![self isKindOfClass:[NavigationMainTableViewController class]]){
[self performSegueWithIdentifier:#"showShopDetail" sender:self];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
What you can do (if i'm sure i understood what you're doing) is create two segue links with differnt identifiers (with a clear name, I like this formatting "fromHereToThere"). Then in your didselect you can just call your segue with an if statement, like so :
if (your condition){
[self performSegueWithIdentifier:#"fromHomeToStatic" sender:self];
}else{
[self performSegueWithIdentifier:#"fromHomeToDetail" sender:self];
}
Then in your prepareForSegue method (the one in comment by default in every controller class) you can choose what data to pass along, with
if ([segue.identifier isEqualToString:#"fromHomeToDetail"])
{
//Manage your usual stuff here for the detail identifier
//Ask me again if you need extra help with that
}
if ([segue.identifier isEqualToString:#"fromHomeToStatic"]){
//Manage here for the static identifier
}
But i'm not really exactly sure what you meant with your question so i might be completly off topic :D
EDIT : Okay apparently you wanna know where you're coming FROM when you're loading your third controller. So here is a way to do that.
In your destination controller, add this in .h
#property (nonatomic) BOOL fromStatic;
(or whatever you want really)
Then in your origin controller, in the prepareForSegue, if you're coming from Static, set the BOOL of the next controller to YES, if not, set it to NO, like this
DetailViewController *dvc = segue.destionationViewController;
dvc.fromStatic = YES; //if you're writing this from the static controller
In the viewDidLoad of the destination controller just check if it's YES or NO and react accordingly.
Am I getting this right or am I still confused with your problem? I'm still not completly sure what you're asking haha :D
Try to use this one. You can set that method for each cell you taping.
[self performSegueWithIdentifier:#"yourIdentifierHere" sender:self];
If you are using Static Cell Prototype . Just drag from cell to the view which you want to push and select push in segue . If you are using dynamic UITableViewCell. You can performSegue in didSelectRowAtIndex Method .

How to pass the in-place edited content back to the previous tableview controller (update the model)

I have two table views, one called mainTableViewController (mtvc), the other called detailTableViewController (dtvc). It's very typical click the accessory button on the main tableview cell bring you to the detail tableview kinda thing.
In the prepareForSegue method, the data passed from the main tableview to detail tableview is a NSMutableArray called item.
And this is how I got it displayed: cell.detailTextLabel.text = self.item[indexPath.row];
The cool thing is I managed to do in-place editing on the detail table view cell (overwrote the NSTableViewCell, added a UITextField as subview to each cell).
everything works, the last thing I spent whole day cannot figure out is how do I update the NSMutableArray item after in-place editing taken place, the ultimate goal is in-place editing, and the main tableview data shall reflect the change.
I tried to use delegation and protocol but it does not work (the in-place edited content didn't got passed back, part of the reason is I don't know how to capture the edited content, it's not like it's a text field with a name, I can't just do updatedContent = self.myTextField.text to grab the change)
I'm running out of ideas, any help would be highly appreciated, thanks.
Here's the prepareForSegue in the main tableview controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"toInventoryDetail"]) {
NSMutableArray *selectedItem = nil;
if (self.searchDisplayController.active) {
selectedItem = _searchResults[[sender row]];
} else {
selectedItem = _appDelegate.items[[sender row]];
}
UPFInventoryDetailTableViewController *idtvc = segue.destinationViewController;
idtvc.item = selectedItem;
}
}
and here's the cellForRowAtIndex at the detail tableview controller
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UPFEditableUITableViewCell *cell = [[UPFEditableUITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
cell.textLabel.text = _appDelegate.title[indexPath.row];
cell.detailTextLabel.text = self.item[indexPath.row];
[cell showEditingField:YES];
return cell;
}
I wrote the delegation but delete them after cause they didn't work.
I had an idea, still using delegation and protocol obviously: when the 'done' button in the detail tableview hit, I go grab all the row contents and build a new array, using delegation to pass this new array back to the main tableview controller, add this new array into the model meanwhile delete the old one. The tricky thing is still HOW CAN I GRAB ALL THE CONTENTS in the detail tableview?
update:
Haha! I think solved half of the puzzle !
here's the solution for the detail tableview controller
- (IBAction)doneUpdate:(UIBarButtonItem *)sender {
[self.delegate addItem:[self newItem]];
}
- (NSMutableArray *)saveItem
{
NSMutableArray *newItem = [[NSMutableArray alloc] init];
NSArray *indexPathes = [self.tableView indexPathsForVisibleRows];
for (NSIndexPath *indexPath in indexPathes) {
UPFEditableUITableViewCell *cell = (UPFEditableUITableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
[newItem addObject:cell.editField.text];
}
return newItem;
}
and here's the main tableview controller
- (void)addItem:(NSArray *)item
{
//take the updated item then insert the items array as new item
[_appDelegate.items addObject:item];
//remove the selected item (the one being updated) from the items array
[_appDelegate.items removeObject:_appDelegate.selectedItem];
[self.tableView reloadData];
[self.navigationController popViewControllerAnimated:YES];
}
When you creating a cell - give tags to your UITextFields
You can collect data entered by its delegate methods - you can either make NSDictionary/ key value pairs or you can add it to NSArray.
- (void)textFieldDidEndEditing:(UITextField *)textField {
if(textField.tag == 11) {
// you can add it to your desired array/dictionary
}
}
OR
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if(textField.tag == 11) {
// you can add it to your desired array/dictionary
}
}
You can use Delegation/Protocol or store this values in NSUserDefault and get it back on mainViewController.
Do you have a separate data model class(classes) for your selectedItem? That would be the appropriate way to persist data between the two TableViewControllers. It can be Core Data or simply a NSMutableArray that lives in memory. The DetailViewController updates the item and saves the changes, then the mainTableViewController reloads the TableView (or even just the data backing the previously edited cell.
Perhaps even consider the Model-View-Controller-Store pattern promoted by BigNerdRanch.

Set iOS Address Book Image in UITableViewCell

I am trying to integrate the AddressBookUI API into my iOS 5 app to display selected content in a table view. I have been able to implement the AddressBook Picker and set it so when a user selects a person from their address book, it populates the label of the cell in the TableView. I would also like it to be able to display the image of the selected person in the same cell if one exists and a default missing picture image if there is not one.
I can't see to get my head around how to store both the name and the image data in the same TableView cell.
Anyone have any suggestions of how I might accomplish this. I have read the developer docs and know i should be using the ABPersonCopyImageDataWithFormat command. I just can't seem to get it to implement into the tableview cell.
Here are the snippets of code I have so far:
// Store the name into memory when the user selects, then dismiss the view.
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
NSString *selectedPerson = (__bridge NSString *)ABRecordCopyCompositeName(person);
[people insertObject:selectedPerson atIndex:0];
if (ABPersonHasImageData(person) == TRUE) {
NSLog(#"Person has an image!");
} else {
NSLog(#"Person does not have an image.");
}
[self dismissModalViewControllerAnimated:YES];
[self.tableView reloadData];
return NO;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PartyCell *cell = (PartyCell *)[tableView dequeueReusableCellWithIdentifier:#"Cell"];
cell.backgroundView = [[GradientView alloc] init];
cell.personLabel.text = [people objectAtIndex:indexPath.row];
cell.personImage.image = [UIImage imageNamed:#"missing.png"]; // THIS NEEDS TO DISPLAY THE SELECTED USERS PICTURE. CURRENTLY SHOWS A DEFAULT USER.
return cell;
}
Thanks!
Found a simple solution: store the image of the selected contact in a new NSMutableArray at index 0 each time.
UIImage *image =[UIImage imageWithData:(__bridge NSData *)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail)];
[peopleImage insertObject:image atIndex:0];
The images can then be loaded like normal into a cell by calling the array in the UITabelView
cell.personImage.image = [peopleImage objectAtIndex:indexPath.row];
First, you get a UIImage from the ABRecordRef:
[UIImage imageWithData:(NSData *)ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail)];
Then, you can set the UITableViewCell's imageView's image like:
[[cell imageView] setImage: image];
Couple other links that may help you:
http://www.chrisdanielson.com/tag/uitableviewcell/
http://goddess-gate.com/dc2/index.php/post/421

Resources