UITableView section not reloading when called - objective-c

I want a section of my table view to reload whenever the ViewWillAppear method is called, I've implemented this like so:
- (void)viewWillAppear:(BOOL)animated {
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:0 inSection:1];
reloadRows = [NSArray arrayWithObjects:rowToReload, nil];
[self.tableView reloadRowsAtIndexPaths:reloadRows withRowAnimation:UITableViewRowAnimationNone];
}
Here is the rowforsection method that indicates which content should appear in each tableview section:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"fadk");
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"PINGAS"];
[self.tableView setAlwaysBounceVertical:YES];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:#"PINGAS"] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
// if ([indexPath section] == 0) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 3, 300, 41)];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 0, 300, 120)];
UIView *paddingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 0)] autorelease];
paddingView.backgroundColor = [UIColor cyanColor];
// if ([indexPath row] == 0) {
if ([indexPath section] == 0) {
NSLog(#"0");
[cell addSubview:textField];
if ([indexPath row] == 0) {
textField.placeholder = #"Title";
}
else{
textField.placeholder = #"Location";
}
}
else if ([indexPath section] == 1) {
NSLog(#"1");
NSDateFormatter *formatter;
NSString *eSString1;
NSString *eEString2;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"h:mm a"];
cell.textLabel.text = #"Starts\nEnds";
cell.textLabel.numberOfLines = 2;
eSString1 = [formatter stringFromDate:eSTime];
eEString2 = [formatter stringFromDate:eEtime];
cell.detailTextLabel.text = [NSString stringWithFormat:#"%#\n%#", eSString1, eEString2];
cell.detailTextLabel.numberOfLines = 2;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else{
NSLog(#"2");
[cell addSubview:textView];
}
textField.delegate = self;
textField.leftView = paddingView;
textField.leftViewMode = UITextFieldViewModeAlways;
textField.adjustsFontSizeToFitWidth = YES;
textField.textColor = [UIColor blackColor];
textField.keyboardType = UIKeyboardTypeAlphabet;
textField.returnKeyType = UIReturnKeyDone;
textField.backgroundColor = [UIColor clearColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
textField.textAlignment = UITextAlignmentLeft;
textField.tag = 0;
//playerTextField.delegate = self;
textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
[textField setEnabled: YES];
[textField release];
textView.delegate = self;
textView.textColor = [UIColor blackColor];
textView.keyboardType = UIKeyboardTypeAlphabet;
textView.returnKeyType = UIReturnKeyDone;
textView.backgroundColor = [UIColor clearColor];
textView.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textView.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
textView.textAlignment = UITextAlignmentLeft;
textView.tag = 0;
[textView release];
// }
}
return cell;
}
This works swimmingly the first load, and I after the first calling of viewWillAppear, but after that the section seems to recycle the data from the first load and the second load, and while it still enters the cellforrow section, it no longer goes into the section I call in the viewWIllAppear section.

The reload should be sandwiched between begin / end updates:
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:reloadRows withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];

Related

UicollectionView didSelectItemAtIndexPath is not called in uiTableviewcell

I am working on chat view. For this I have used this code :Chat Code
This is working fine. Now I have used UIcollectionView in UItableViewCell. Collection view is working fine. But the issue is didselect method is not called of UICollectionView as well as UITableView. Please help me. I need your help very badly.
I have used this code in UITableViewCell Class:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor clearColor];
if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0f) {
self.textLabel.backgroundColor = [UIColor whiteColor];
}
self.textLabel.font = [UIFont systemFontOfSize:14.0f];
self.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.textLabel.numberOfLines = 0;
self.textLabel.textAlignment = NSTextAlignmentLeft;
self.textLabel.textColor = [UIColor blackColor];
_timestampLabel = [[UILabel alloc] init];
_timestampLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_timestampLabel.textAlignment = NSTextAlignmentCenter;
_timestampLabel.backgroundColor = [UIColor clearColor];
_timestampLabel.font = [UIFont systemFontOfSize:12.0f];
_timestampLabel.textColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:1.0];
_timestampLabel.frame = CGRectMake(0.0f, 12, self.bounds.size.width, 18);
[self.contentView addSubview:_timestampLabel];
messageBackgroundView = [[UIImageView alloc] initWithFrame:self.textLabel.frame];
[self.contentView insertSubview:messageBackgroundView belowSubview:self.textLabel];
self.AvatarImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5,10+TOP_MARGIN, 50, 50)];
[self.contentView addSubview:self.AvatarImageView];
CALayer * l = [self.AvatarImageView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:self.AvatarImageView.frame.size.width/2.0];
self.selectionStyle = UITableViewCellSelectionStyleNone;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[self.collectionView registerNib:[UINib nibWithNibName:#"ImageCollection" bundle:nil] forCellWithReuseIdentifier:#"Cell"];
[self.collectionView setUserInteractionEnabled:YES];
self.collectionView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.collectionView];
[messageBackgroundView setUserInteractionEnabled:YES];
[self.contentView setUserInteractionEnabled:YES];
// UITapGestureRecognizer *lpgr // = [[UITapGestureRecognizer alloc] // initWithTarget:self action:#selector(tapRecognized:)]; // lpgr.numberOfTapsRequired
= 1; // lpgr.delegate = self; // [self.collectionView addGestureRecognizer:lpgr];
}
[self setUserInteractionEnabled:YES];
return self; }
In UIViewController I have used this code in tableView cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *L_CellIdentifier = #"SPHTextBubbleCell";
self.documentsArray = [[NSMutableArray alloc]init];
self.documentsArray = [[self.messagesArray objectAtIndex:indexPath.row]valueForKey:#"Attachments"];
SPHTextBubbleCell *cell = [tableView dequeueReusableCellWithIdentifier:L_CellIdentifier];
cell.userInteractionEnabled = YES;
if (cell == nil)
{
cell = [[SPHTextBubbleCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:L_CellIdentifier];
}
// cell.bubbletype=(([[[self.messagesArray objectAtIndex:indexPath.row]valueForKey:#"MessageFromId"]intValue] == 1))?#"LEFT":#"RIGHT";
if ([[[self.messagesArray objectAtIndex:indexPath.row]valueForKey:#"MessageFromId"]intValue] == 1) {
cell.bubbletype = #"RIGHT";
}
else
{
cell.bubbletype = #"LEFT";
}
[cell setBackgroundColor:[UIColor clearColor]];
cell.textLabel.text = [[self.messagesArray objectAtIndex:indexPath.row]valueForKey:#"Content"];
cell.textLabel.tag=indexPath.row;
NSString *dateString = [NSString stringWithFormat:#"%#",[self mfDateFromDotNetJSON:[[self.messagesArray objectAtIndex:indexPath.row]valueForKey:#"UpdatedOn"]]];
NSLog(#"dateString..%#",dateString);
NSString *myString = [NSString stringWithFormat:#"%#",dateString];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = #"yyyy-MM-dd HH:mm:ss ZZZ";
NSDate *yourDate = [dateFormatter dateFromString:myString];
// NSTimeZone *utc = [NSTimeZone timeZoneWithAbbreviation:#"UTC"];
// [dateFormatter setTimeZone:utc];
dateFormatter.dateFormat = #"dd-MMM-yy HH:mm";
NSString *newString = [dateFormatter stringFromDate:yourDate];
NSLog(#"newString..%#",newString);
if ([self.documentsArray count]!=0)
{
cell.CustomDelegate = self;
[cell.collectionView setUserInteractionEnabled:YES];
[cell.collectionView setDelegate:self];
[cell.collectionView setDataSource:self];
cell.collectionView.delegate =self;
cell.collectionView.dataSource = self;
[cell.collectionView reloadData];
[cell.collectionView setHidden:NO];
[cell.collectionView setBackgroundColor:[UIColor clearColor]];
}
else
{
[cell.collectionView setHidden:YES];
}
cell.collectionView.tag =indexPath.row;
cell.timestampLabel.text = newString;
[cell.AvatarImageView sd_setImageWithURL:([[[self.messagesArray objectAtIndex:indexPath.row]valueForKey:#"MessageFromId"]intValue] == 1)?[NSURL URLWithString:[NSString stringWithFormat:#"%#%#",imageURLLive,[[[self.messagesArray objectAtIndex:indexPath.row]valueForKey:#"SellerPicture"] valueForKey:#"PictureUrl"]]]:[NSURL URLWithString:[NSString stringWithFormat:#"%#%#",imageURLLive,[[[self.messagesArray objectAtIndex:indexPath.row]valueForKey:#"BuyerPicture"] valueForKey:#"PictureUrl"]]]
placeholderImage:[UIImage imageNamed:#"Nav-profile1.png"]];
return cell;
}
Thanks in advance.
If your problem is that your UICollectionView taps do not cause the UITableViewCell it is in to be selected then you can bypass this by subclassing UICollectionView and modifying the hitTest function to your liking.
See my answer here.
This one lets you tap on anything outside of collection view items to select the table cell, but collection view items themselves will block the taps and process them as needed.
Modifying the hitTest method wasn't working in my case. I decided to use UITapGestureRecognizer.
// Custom UITableViewCell
override func awakeFromNib() {
super.awakeFromNib()
let tapGR = UITapGestureRecognizer(target: self, action: #selector(collectionViewTapped(_:)))
tapGR.numberOfTapsRequired = 1
self.collectionView.addGestureRecognizer(tapGR)
}
func collectionViewTapped(gr: UITapGestureRecognizer) {
let point = gr.locationInView(self.collectionView)
if let indexPath = self.collectionView.indexPathForItemAtPoint(point) {
// Do stuff
}
}
Don't forget to set delegate and dataSource.
self.tableView.delegate = self;
self.tableView.dataSource = self;

Disable UITextField in UITableViewCell

I have a UITextField in a UITableViewCell.
Even though I set -
textField.userInteractionEnabled = NO;
textField.enabled = NO
But when I click on the table cell which contains the textField, the keyboard comes up for the textfield.
Why is this happening and how can I prevent it?
EDIT: Strangely this is happening when I first set some text in the textfield. When the textfield is empty, it is not editable.
EDIT: Code for cellForRowAtIndexPath -
cell = [tableView dequeueReusableCellWithIdentifier:#"CellIdentifier"];
cell.accessoryType = UITableViewCellAccessoryNone;
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, cell.bounds.size.width - 20, cell.bounds.size.height - 20)];
textField.font = [UIFont systemFontOfSize:15];
textField.textColor = [UIColor blackColor];
UIColor *placeholderColor = [UIColor colorWithRed:146/255.0 green:146/255.0 blue:146/255.0 alpha:1];
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:[self getPlaceHolderTextForIndexPath:indexPath] attributes:#{NSForegroundColorAttributeName : placeholderColor}];
textField.keyboardType = [self getKeyboardTyeForIndexPath:indexPath];
textField.returnKeyType = UIReturnKeyDone;
textField.backgroundColor = [UIColor clearColor];
textField.textAlignment = NSTextAlignmentLeft;
textField.autocapitalizationType = [self getAutocapitaliztionTypeForIndexPath:indexPath];
textField.tag = 1;
if (_editingNotAllowed) {
[textField setText:[self getTextForTextFieldWithIndexPath:indexPath]];
[textField setUserInteractionEnabled:NO];
textField.enabled = NO;
} else {
[textField setUserInteractionEnabled:YES];
}
[cell.contentView addSubview:textField];
You should create an UITableViewCell as shown in this repo :)
https://github.com/breeno/EditingUITableView
And use your custom UITableViewCell like this:
if(condition){ // Check the row must be TextField
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier: nil];
if(!cell){
cell = [[CustomCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: nil];
}
cell.label.text = #"Title Row"; //UITextLabel Title
UIColor *placeholderColor = [UIColor colorWithRed:146/255.0 green:146/255.0 blue:146/255.0 alpha:1];
cell.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:[self getPlaceHolderTextForIndexPath:indexPath] attributes:#{NSForegroundColorAttributeName : placeholderColor}];
cell.textField.returnKeyType = UIReturnKeyDone;
cell.textField.backgroundColor = [UIColor clearColor];
cell.textField.textAlignment = NSTextAlignmentLeft;
cell.textField.tag = 1;
} else { // Normal UITableViewCell
}

Dealing with Core data one-to-many relationship

I have been beating my head over this issue for some time now and my last hope is Stack Overflow.
Here is the app idea. I have two entities modeled in core data. The Golfer entity has a one to many relationship with FittingSession, so each golfer is capable of having more than one fitting session. I am not able to post an image for the data models as I am a new user.
But here are the details:
ENTITY: GOLFER and FITTING SESSION
Attributes for Golfer - first_name, last_name, emailId, contactNum, picture
Relationship : NSSet * fittingSessions
Attributes for Fitting Sessions - session_number, date, location, notes.
Relationship: Golfer * whoPlayed
I am working on one view controller called ViewManager (kinda base view for all my classes) and it has 2-3 Custom UIViews inside it. I animate them in and out whenever I need them.
I am getting my Golfers list-collection in a tableview from NSFetchedResultsController and getting the Fitting Sessions attributes in a tableview by the same technique using NSFetchedResultsController. My question is: How do I get a specific fitting session for a specific golfer? What do I have to write in TableViewDidSelectRow Method of Parent( Golfer )View? How do I deal with this one to many relationship? Here's my code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if(tableView == mGolferTblView)
{
NSInteger count = [[self.fetchedResultsController sections] count];
NSLog(#"count section GOLFER TABLE VIEW=%d", count);
return count;
}
else if(tableView == mFittingTblView)
{
return 1;
}
else {
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(tableView == mGolferTblView)
{
id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
NSLog(#"count for array ROWS for GOLFERS =%d", [sectionInfo numberOfObjects]);
return [sectionInfo numberOfObjects];
}
else if(tableView == mFittingTblView)
{
mFittingSessionArray = [mFittingSessionSet allObjects];
NSLog(#"array here is=%#", mFittingSessionArray);
NSLog(#"count for ROWS in FITTING SESSIONS table view=%d", [mFittingSessionArray count]);
return [mFittingSessionArray count];
// id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fittingFetchedResultsController sections] objectAtIndex:section];
// NSLog(#"count for array ROWS for FITTING SESSIONS =%d", [sectionInfo numberOfObjects]);
// return [sectionInfo numberOfObjects];
}
else {
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == mGolferTblView)
{
static NSString *CellIdentifier = #"Cell";
static NSInteger fullNameTag = 1;
static NSInteger imageTag = 2;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UILabel *fakeLbl =[[UILabel alloc] initWithFrame:CGRectMake(100, 30, 100, 30)];
fakeLbl.backgroundColor = [UIColor clearColor];
fakeLbl.textColor = [UIColor grayColor];
fakeLbl.text=#"3 days ago";
[cell.contentView addSubview:fakeLbl];
[fakeLbl release];
UIImageView *btnImage =[[UIImageView alloc] initWithFrame:CGRectMake(250, 40, 25, 28)];
btnImage.image = [UIImage imageNamed:#"badge_25x28.png"];
btnImage.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:btnImage];
[btnImage release];
UILabel *fullNameLbl =[[UILabel alloc] initWithFrame:CGRectMake(100, 0, 300, 30)];
fullNameLbl.backgroundColor = [UIColor clearColor];
fullNameLbl.textColor = [UIColor whiteColor];
fullNameLbl.numberOfLines = 1;
fullNameLbl.adjustsFontSizeToFitWidth = YES;
fullNameLbl.tag = fullNameTag;
[cell.contentView addSubview:fullNameLbl];
[fullNameLbl release];
UIImageView *imageView =[[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 71, 91)];
imageView.backgroundColor = [UIColor clearColor];
imageView.tag = imageTag;
[cell.contentView addSubview:imageView];
[imageView release];
}
mGolfer = [self.fetchedResultsController objectAtIndexPath:indexPath];
UILabel * fullNameLbl = (UILabel *) [cell.contentView viewWithTag:fullNameTag];
fullNameLbl.text = mGolfer.fullName;
UIImageView * imgView = (UIImageView *) [cell.contentView viewWithTag:imageTag];
imgView.image = mGolfer.picture;
return cell;
}
if(tableView == mFittingTblView)
{
static NSString *CellIdentifier = #"Cell";
static NSInteger locationTag = 1;
static NSInteger notesTag = 2;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UIImageView *iconImage =[[UIImageView alloc] initWithFrame:CGRectMake(10, 40, 11, 18)];
iconImage.image = [UIImage imageNamed:#"icon_locationmarker_11x18.png"];
iconImage.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:iconImage];
[iconImage release];
UILabel *fakeDateLbl =[[UILabel alloc] initWithFrame:CGRectMake(180, 15, 100, 20)];
fakeDateLbl.backgroundColor = [UIColor clearColor];
fakeDateLbl.textColor = [UIColor grayColor];
fakeDateLbl.text=#"apr.30.2012";
[cell.contentView addSubview:fakeDateLbl];
[fakeDateLbl release];
UIImageView *fakeImage1 =[[UIImageView alloc] initWithFrame:CGRectMake(25, 90, 43, 43)];
fakeImage1.image = [UIImage imageNamed:#"icon_catDriver_43x43.png"];
fakeImage1.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage1];
[fakeImage1 release];
UIImageView *fakeImage2 =[[UIImageView alloc] initWithFrame:CGRectMake(70, 90, 43, 43)];
fakeImage2.image = [UIImage imageNamed:#"icon_catFairway_43x43.png"];
fakeImage2.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage2];
[fakeImage2 release];
UIImageView *fakeImage3 =[[UIImageView alloc] initWithFrame:CGRectMake(115, 90, 43, 43)];
fakeImage3.image = [UIImage imageNamed:#"icon_catHybrid_43x43.png"];
fakeImage3.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage3];
[fakeImage3 release];
UIImageView *fakeImage4 =[[UIImageView alloc] initWithFrame:CGRectMake(160, 90, 43, 43)];
fakeImage4.image = [UIImage imageNamed:#"icon_catIron_43x43.png"];
fakeImage4.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage4];
[fakeImage4 release];
UIImageView *fakeImage5 =[[UIImageView alloc] initWithFrame:CGRectMake(205, 90, 43, 43)];
fakeImage5.image = [UIImage imageNamed:#"icon_catWedge_43x43.png"];
fakeImage5.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage5];
[fakeImage5 release];
UILabel *sessionLbl =[[UILabel alloc] initWithFrame:CGRectMake(10, 7, 150, 30)];
sessionLbl.backgroundColor = [UIColor clearColor];
sessionLbl.textColor = [UIColor redColor];
sessionLbl.text = #"session";
sessionLbl.font = [UIFont boldSystemFontOfSize:18];
[cell.contentView addSubview:sessionLbl];
[sessionLbl release];
UILabel *locationLbl =[[UILabel alloc] initWithFrame:CGRectMake(30, 32, 270, 30)];
locationLbl.backgroundColor = [UIColor clearColor];
locationLbl.textColor = [UIColor whiteColor];
locationLbl.tag = locationTag;
[cell.contentView addSubview:locationLbl];
[locationLbl release];
UILabel *notesLbl =[[UILabel alloc] initWithFrame:CGRectMake(30, 54, 270, 30)];
notesLbl.backgroundColor = [UIColor clearColor];
notesLbl.textColor = [UIColor whiteColor];
notesLbl.tag = notesTag;
[cell.contentView addSubview:notesLbl];
[notesLbl release];
}
mFittingSessionArray = [mFittingSessionSet allObjects];
mFittingSession = [mFittingSessionArray objectAtIndex:indexPath.row];
UILabel *locationLbl = (UILabel *)[cell.contentView viewWithTag:locationTag];
locationLbl.text = mFittingSession.locationUppercase;
NSLog(#"location=%#", mFittingSession.locationUppercase);
UILabel *notesLbl = (UILabel *)[cell.contentView viewWithTag:notesTag];
notesLbl.text = mFittingSession.notesInQuotes;
return cell;
}
return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == mGolferTblView)
{
mGolfer = (Golfer *)[self.fetchedResultsController objectAtIndexPath:indexPath];
mGolferNameLbl.text = mGolfer.fullName;
mGolferHeaderPicture.image = mGolfer.picture;
NSSet * fittingSessionSet = mGolfer.fittingSessions;
mFittingSessionArray = [fittingSessionSet allObjects];
NSLog(#"count for sessions=%d", [mFittingSessionArray count]);
NSLog(#"fiting sessions for golfer %# are= %#", mGolfer.first_name, mFittingSessionArray);
}
}
Also, this is how I add a new fitting session to a particular golfer:
- (IBAction)addNewSession:(id)sender
{
AppDelegate * applicationDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
NSManagedObjectContext * context = [applicationDelegate managedObjectContext];
mFittingSession=(FittingSession*) [NSEntityDescription insertNewObjectForEntityForName:#"FittingSession" inManagedObjectContext:context];
mFittingSession.location=mLocationTextField.text;
mFittingSession.notes=mNotesTxtView.text;
**mFittingSession.whoPlayed = self.golfer;** This is setting the relationship (whoPlayed is inverse relation to golfer provided by core data)
}
Please help me in this as I am really not getting how to deal with the relationship in core data. Please provide some code or snippets so that I can know what's going on.
Thank you
Maybe I don't understand your question correctly, but to get a Golfer's Fitting Session is really easy. So in the first code block you just do the following:
mGolfer = (Golfer *)[self.fetchedResultsController objectAtIndexPath:indexPath];
NSSet *fittingSession = mGolfer.fittingSessions;
You can access the relations as you would access the other attributes.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if(tableView == mGolferTblView)
{
NSInteger count = [[self.fetchedResultsController sections] count];
NSLog(#"count section GOLFER TABLE VIEW=%d", count);
return count;
}
else if(tableView == mFittingTblView)
{
NSInteger countOfSections = 1;
NSLog(#"count section FITTING SESSION VIEW=%d", countOfSections);
return countOfSections;
}
else {
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(tableView == mGolferTblView)
{
id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
NSLog(#"count for ROWS in GOLFERS table view =%d", [sectionInfo numberOfObjects]);
return [sectionInfo numberOfObjects];
}
else if(tableView == mFittingTblView)
{
mFittingSessionArray = [mFittingSessionSet allObjects];
NSLog(#"array here is=%#", mFittingSessionArray);
NSLog(#"count for ROWS in FITTING SESSIONS table view=%d", [mFittingSessionArray count]);
return [mFittingSessionArray count];
}
else {
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == mGolferTblView)
{
static NSString *CellIdentifier = #"Cell";
static NSInteger fullNameTag = 1;
static NSInteger imageTag = 2;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UILabel *fullNameLbl =[[UILabel alloc] initWithFrame:CGRectMake(100, 0, 300, 30)];
fullNameLbl.backgroundColor = [UIColor clearColor];
fullNameLbl.textColor = [UIColor whiteColor];
fullNameLbl.numberOfLines = 1;
fullNameLbl.adjustsFontSizeToFitWidth = YES;
fullNameLbl.tag = fullNameTag;
[cell.contentView addSubview:fullNameLbl];
[fullNameLbl release];
UIImageView *imageView =[[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 71, 91)];
imageView.backgroundColor = [UIColor clearColor];
imageView.tag = imageTag;
[cell.contentView addSubview:imageView];
[imageView release];
}
mGolfer = [self.fetchedResultsController objectAtIndexPath:indexPath];
UILabel * fullNameLbl = (UILabel *) [cell.contentView viewWithTag:fullNameTag];
fullNameLbl.text = mGolfer.fullName;
UIImageView * imgView = (UIImageView *) [cell.contentView viewWithTag:imageTag];
imgView.image = mGolfer.picture;
return cell;
}
else if(tableView == mFittingTblView)
{
**mFittingSessionArray = [mFittingSessionSet allObjects];** // Added this line
static NSString *CellIdentifier = #"Cell";
static NSInteger locationTag = 1;
static NSInteger notesTag = 2;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UILabel *locationLbl =[[UILabel alloc] initWithFrame:CGRectMake(30, 32, 270, 30)];
locationLbl.backgroundColor = [UIColor clearColor];
locationLbl.textColor = [UIColor whiteColor];
locationLbl.tag = locationTag;
[cell.contentView addSubview:locationLbl];
[locationLbl release];
UILabel *notesLbl =[[UILabel alloc] initWithFrame:CGRectMake(30, 54, 270, 30)];
notesLbl.backgroundColor = [UIColor clearColor];
notesLbl.textColor = [UIColor whiteColor];
notesLbl.tag = notesTag;
[cell.contentView addSubview:notesLbl];
[notesLbl release];
}
mFittingSession = [mFittingSessionArray objectAtIndex:indexPath.row];
UILabel *locationLbl = (UILabel *)[cell.contentView viewWithTag:locationTag];
UILabel *notesLbl = (UILabel *)[cell.contentView viewWithTag:notesTag];
locationLbl.text = mFittingSession.locationUppercase;
notesLbl.text = mFittingSession.notesInQuotes;
return cell;
}
else {
}
return 0;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == mGolferTblView)
{
if(self.editing)
{
[self.golferTblView deselectRowAtIndexPath:indexPath animated:YES];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^ {
mEditGolfersView.hidden = NO;
mEditGolfersView.frame = CGRectMake(305, mEditGolfersView.frame.origin.y, mEditGolfersView.frame.size.width, mEditGolfersView.frame.size.height);
}
completion:NULL];
mGolfer = (Golfer *) [self.fetchedResultsController objectAtIndexPath:indexPath];
mEditFirstName.text = mGolfer.first_name;
mEditMiddleName.text = mGolfer.middle_name;
mEditLastName.text = mGolfer.last_name;
mEditEmailField.text = mGolfer.email_id;
mEditContactNum.text = mGolfer.contactNumber;
mEditPictureView.image = mGolfer.picture;
mShowDataBtn.enabled = NO;
return;
}
[self.golferTblView deselectRowAtIndexPath:indexPath animated:YES];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^ {
mGolfersView.frame = CGRectMake(-260, mGolfersView.frame.origin.y, mGolfersView.frame.size.width, mGolfersView.frame.size.height);
}
completion:^(BOOL finished){
mGolfersView.hidden = YES;
}];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn
animations:^ {
mFittingSessionView.hidden = NO;
mFittingSessionView.frame = CGRectMake(-19, mFittingSessionView.frame.origin.y, mFittingSessionView.frame.size.width, mFittingSessionView.frame.size.height);
}
completion:NULL];
mGolfer = (Golfer *)[self.fetchedResultsController objectAtIndexPath:indexPath];
mGolferNameLbl.text = mGolfer.fullName;
mGolferHeaderPicture.image = mGolfer.picture;
mFittingSessionSet = mGolfer.fittingSessions;
mFittingSessionArray = [mFittingSessionSet allObjects];
NSLog(#"count for sessions=%d", [mFittingSessionArray count]);
NSLog(#"fiting sessions for golfer %# are= %#", mGolfer.first_name, mFittingSessionArray);
**[mFittingTblView reloadData];** // Added this and this reloads the data for fitting view.
}
}

Remove top shadow in my grouped UITableView?

I am a little OCD and this is driving me insane. I have been messing around with these settings for a long time.
I have a UITableView grouped that I have a shadow on the top. When you tap the top cell, it removes. What gives?
I've been stressing over this for the past hour or so. Is there a simple solution for this? Or am I just going insane?
Thanks,
Coulton
EDIT:
viewDidLoad:
formTableView.backgroundColor = [UIColor clearColor];
formTableView.layer.borderColor = [UIColor clearColor].CGColor;
formTableView.separatorColor = [UIColor colorWithRed:(194.0 / 255.0) green:(194.0 / 255.0) blue:(194.0 / 255.0) alpha: 1];
Here is how I display my cells. WARNING: It's a lot of code. There's a bunch of stuff in there you will have to sort through, so sort through it at your own risk! :)
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
// What to do when you click delete.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
//RootViewController.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return [formDataOne count];
} else {
return [formDataTwo count];
}
}
//RootViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
// Set up the cell...
NSString *cellValue;
if (indexPath.section == 0) {
cellValue = [formDataOne objectAtIndex:indexPath.row];
} else {
cellValue = [formDataTwo objectAtIndex:indexPath.row];
}
if (indexPath.section == 0) {
cell.text = #"";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.row == 0) {
addTitle = [[UITextField alloc] initWithFrame:CGRectMake(13, 13, 280, 20)];
addTitle.borderStyle = UITextBorderStyleNone;
addTitle.textColor = [UIColor blackColor]; //text color
addTitle.font = [UIFont systemFontOfSize:16.0]; //font size
addTitle.placeholder = #"Album Name"; //place holder
addTitle.backgroundColor = [UIColor clearColor]; //background color
addTitle.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
addTitle.keyboardType = UIKeyboardTypeDefault; // type of the keyboard
addTitle.returnKeyType = UIReturnKeyDone; // type of the return key
addTitle.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
addTitle.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
[cell.contentView addSubview:addTitle];
} else if (indexPath.row == 1) {
// Set up loading text and show it
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 13, 280, 20)];
myLabel.text = #"Private Album";
myLabel.textColor = [UIColor blackColor];
myLabel.textAlignment = UITextAlignmentLeft;
myLabel.backgroundColor = [UIColor clearColor];
myLabel.font = [UIFont fontWithName:#"Helvetica" size: 16.0];
myLabel.numberOfLines = 0;
//[myLabel sizeToFit];
privateSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[privateSwitch addTarget:self action:#selector(switchToggled:) forControlEvents: UIControlEventTouchUpInside];
[cell.contentView addSubview:privateSwitch];
//[privateSwitch setOn:NO animated:NO];
if ([howToDisplay isEqualToString:#"no"]) {
[privateSwitch setOn:NO animated:NO];
} else {
[privateSwitch setOn:YES animated:NO];
}
[cell.contentView addSubview:myLabel];
} else {
// Set up loading text and show it
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 13, 280, 20)];
myLabel.text = #"Comments";
myLabel.textColor = [UIColor blackColor];
myLabel.textAlignment = UITextAlignmentLeft;
myLabel.backgroundColor = [UIColor clearColor];
myLabel.font = [UIFont fontWithName:#"Helvetica" size: 16.0];
myLabel.numberOfLines = 0;
//[myLabel sizeToFit];
[cell.contentView addSubview:myLabel];
commentsSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[cell.contentView addSubview:commentsSwitch];
[commentsSwitch setOn:YES animated:NO];
}
} else {
//cell.text = cellValue;
UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectMake(48, 12, 130, 20)];
labelOne.text = cellValue;
labelOne.textColor = [UIColor blackColor];
[labelOne setFont:[UIFont boldSystemFontOfSize:16]];
labelOne.textAlignment = UITextAlignmentLeft;
labelOne.backgroundColor = [UIColor clearColor];
//labelOne.font = [UIFont fontWithName:#"Helvetica"];
labelOne.numberOfLines = 0;
[cell.contentView addSubview:labelOne];
if (indexPath.row == 0) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else if (indexPath.row == 1) {
int countFacebook = [dataCeter.connectionFacebookArray count];
if (countFacebook == 0) {
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
} else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
} else if (indexPath.row == 2) {
//} else if (indexPath.row == 3) {
} else if (indexPath.row == 3) {
int countTumblr = [dataCeter.connectionTumblrArray count];
if (countTumblr == 0) {
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
} else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
} else if (indexPath.row == 4) {
} else if (indexPath.row == 5) {
} else {
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
}
// Set imageView with correct thumbnail
UIImage *theImage;
if ([cellValue isEqualToString:#"Facebook"]) {
theImage = [UIImage imageNamed:#"icon_small_facebook.png"];
int countFacebook = [dataCeter.connectionFacebookArray count];
NSLog(#"facebook? %d // %#", countFacebook, dataCeter.connectionFacebookArray);
if (countFacebook != 0) {
facebookSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[cell.contentView addSubview:facebookSwitch];
[facebookSwitch setOn:YES animated:NO];
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
} else if ([cellValue isEqualToString:#"Twitter"]) {
theImage = [UIImage imageNamed:#"icon_small_twitter.png"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if ([cellValue isEqualToString:#"Flickr"]) {
theImage = [UIImage imageNamed:#"icon_small_flickr.png"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if ([cellValue isEqualToString:#"Tumblr"]) {
theImage = [UIImage imageNamed:#"icon_small_tumblr.png"];
int countTumblr = [dataCeter.connectionTumblrArray count];
if (countTumblr != 0) {
tumblrSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[cell.contentView addSubview:tumblrSwitch];
[tumblrSwitch setOn:YES animated:NO];
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
} else if ([cellValue isEqualToString:#"Email"]) {
theImage = [UIImage imageNamed:#"icon_small_email.png"];
int countEmail = [dataCeter.connectionEmailArray count];
} else if ([cellValue isEqualToString:#"MMS"]) {
theImage = [UIImage imageNamed:#"icon_small_mms.png"];
int countMMS = [dataCeter.connectionSMSArray count];
} else if ([cellValue isEqualToString:#"Photostream"]) {
theImage = [UIImage imageNamed:#"icon_small_photostream.png"];
cell.accessoryType = UITableViewCellAccessoryNone;
photostreamSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[cell.contentView addSubview:photostreamSwitch];
[photostreamSwitch setOn:YES animated:NO];
} else {
theImage = nil;
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.imageView.image = theImage;
return cell;
}
Set your table view's separator style to UITableViewCellSeparatorStyleSingleLine. It's currently being set to UITableViewCellSeparatorStyleSingleLineEtched, which gives the effect of a doubled top border on the iPhone (it looks more detailed on iOS 5, and on iOS 3.2 and 4 on the iPad).
You're not insane, it looks like there is an extra pixel in there.
Try taking out "Sharing" and see if it still happens. Curious to see if the shadow is on "Sharing" or the table itself.
If that's the case, then you know your header view has a problem, not the table view.

UITextField in UITableView cell is returning null

I've been banging my head against the wall on this one for quite some time now. Any input or direction is greatly appreciated.
So the goal is the create a log in form from text fields in a table. That user info, once collected will be passed on to an array in a seperate view controller so in can stored in a "favourites" list.
So I've created the form which looks great and all but when I console out the form results the fields are return (null). I've picked the site for answers but can't anything exact. Below is the cellForRowAtIndexPath: method I feel that maybe the issue is where I'm creating the textFields. Again, any input is appreciated!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:[indexPath section]]];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:CellIdentifier] autorelease];
textField = [[UITextField alloc] initWithFrame:CGRectMake(120, 13, 375, 30)];
[textField retain];
}
textField.adjustsFontSizeToFitWidth = NO;
textField.font = [UIFont fontWithName:#"Helvetica" size:14.0];
textField.textColor = [UIColor darkGrayColor];
textField.returnKeyType = UIReturnKeyDone;
textField.backgroundColor = [UIColor clearColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
textField.textAlignment = UITextAlignmentLeft;
textField.clearButtonMode = UITextFieldViewModeNever;
textField.delegate = self;
if ([indexPath section] == 0) {
switch (indexPath.row) {
case 0:
textField.placeholder = #"Optional";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 0;
break;
case 1:
textField.placeholder = #"";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 1;
break;
case 2:
textField.placeholder = #"";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 2;
break;
case 3:
textField.placeholder = #"";
textField.secureTextEntry = YES;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 3;
break;
case 4:
textField.placeholder = #"Optional";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 4;
break;
case 5:
textField.placeholder = #"Optional";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeNumberPad;
textField.tag = 5;
break;
}
}
[textField setEnabled: YES];
[cell addSubview:textField];
cell.textLabel.text = [listData objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.editing = YES;
return cell;
}
The textField variable (I assume it is an ivar in the class or a static global variable) is your main problem. You create a new text field each time you create a new cell, which is fine, but then you add it to a cell every time the cellForRowAtIndexPath method is called. Since cells are reused this will screw things up.
Your code need to look something like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:[indexPath section]]];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.editing = YES;
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(120, 13, 375, 30)];
textfield.tag = 1;
textField.adjustsFontSizeToFitWidth = NO;
textField.font = [UIFont fontWithName:#"Helvetica" size:14.0];
textField.textColor = [UIColor darkGrayColor];
textField.returnKeyType = UIReturnKeyDone;
textField.backgroundColor = [UIColor clearColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
textField.textAlignment = UITextAlignmentLeft;
textField.clearButtonMode = UITextFieldViewModeNever;
textField.delegate = self;
[textField setEnabled: YES];
[cell.contentView addSubview:textField];
[textField release];
}
UITextField *textField = (UITextField *) [cell.contentView viewWithTag:1];
if ([indexPath section] == 0) {
switch (indexPath.row) {
case 0:
textField.placeholder = #"Optional";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
break;
case 1:
textField.placeholder = #"";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
break;
case 2:
textField.placeholder = #"";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
break;
case 3:
textField.placeholder = #"";
textField.secureTextEntry = YES;
textField.keyboardType = UIKeyboardTypeDefault;
break;
case 4:
textField.placeholder = #"Optional";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
break;
case 5:
textField.placeholder = #"Optional";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeNumberPad;
break;
}
}
textField.text = [listData objectAtIndex:indexPath.row];
return cell;
}
Not sure this does exactly what you want but it should point you in the right direction.
Create a custom cell to place your text field, for the love of god. You shouldn't have addSubview: related code in your tableView:cellForRowAtIndexPath:; just code that allocates the cell, and configures the cell enough so that the cell itself can display things they way you want them.
Look at the table view suite for an example of how to use custom cells. I believe 4_ and 5_ have custom cells.