I am making an app that generates a UITableView from data. I have a custom UITableViewCell that contains a UIButton with text. The title of one of the generated buttons is too long for the UIButton, but isn't getting truncated as I have selected in the UIStoryBoard. The cells are getting created in my UITableViewController function
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath as normal for prototype cells.
I can't add images because I'm a new user, but here are a couple links to images:
UIStoryBoard Settings: truncate setting
The title bleeding outside the boundaries of the UIButton: overflowing text
Does anyone know how to fix this. It was working earlier. I changed the size of the UIButton and the font of the title text, but I don't think that should make a difference.
Here's the code where I'm setting button's text inside - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
CellIdentifier = #"PopoverCell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
((MSPopoverCell *)cell).nameLabel.text = data.FullName; //setting the label, works fine
[((MSPopoverCell *)cell).button setTitle:data.DisplayString forState:UIControlStateNormal];//setting the button title, bleeds over
Also, I'm new to stackoverflow, so if I have missed anything that I should include, please give me some friendly advice.
Thanks,
Max
Related
In my tableViewCell, I am trying to display dynamic content from CoreData string object in a textView with a background image. When the tableView is loading for the first Time, background image is stretching to right and text content in textView is trimming, but when I scroll the tableView, rect of background image is appearing as expected however, textView content is still trimming. can anyone please tell me what default methods will system call internally when we scroll a tableView? Because some method is setting my background Image rect correctly which i am failing to set in initial loading of tableView.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Many more please check tableview data delegate and data source Methods.
Hello guys i think almost everyone who is in ios development may come across the issue of reuse of the UITableCell by using following code line.
RZRestaurantListingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
I have search lot about this but not getting any desire answer so please help me out in this case.
I have the same issue as most of iPhone developer having after reusing the cell.
I have the UIProgressView inside my cell and one button is there for downloading the video and i am showing the progress there in progress view how much is left.
So Now what i have problem is when i have more data and going out of the screen at that time i am press the download button on very first row of the UITableviewCell then i am scrolling down so the progress also shown in bottom random one cell so the UI changes in two cell rather then one.
You need to implement -prepareForReuse method in your custom cell class and set all cell properties to default value.
- (void)prepareForReuse
If a UITableViewCell object is reusable—that is, it has a reuse
identifier—this method is invoked just before the object is returned
from the UITableView method dequeueReusableCellWithIdentifier:. For
performance reasons, you should only reset attributes of the cell that
are not related to content, for example, alpha, editing, and selection
state. The table view's delegate in tableView:cellForRowAtIndexPath:
should always reset all content when reusing a cell. If the cell
object does not have an associated reuse identifier, this method is
not called. If you override this method, you must be sure to invoke
the superclass implementation.
Refer here for more, https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/#//apple_ref/occ/instm/UITableViewCell/prepareForReuse
You need to assign a progress value inside the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
RZRestaurantListingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// If the cell is reused, the `-prepareForReuse:` of `UITableViewCell` will be called.
//!! Assign current progress value to this cell, otherwise, the progressBar.value may look like a random value.
//!! Because the current cell is reused from a disappeared cell.
cell.progressBar.value = ... ;
return cell;
}
The design may be complex, because the progress may be updated continuously when the cell is on the screen.
Use prepareforreuse method to clear content of cell before using it... e.g.
-(void)prepareForReuse
{
[super prepareForReuse];
self.textLabel.text = #"";
self.detailTextLabel.text = #"";
self.imageView.image = nil;
}
My table has cells which have several labels. I want one of these labels to fit its size so text begins right below the Title (remember that Labels align text vertically unless you fit its container).
Problem is, the very first time the table is loaded all labels' texts are succesfully populated but label sizes don't actually graphically apply until the NEXT time a refresh is asked. (if I ask for a reloadData with the exact same information, the labels' sizes work flawlessly).
This is some of my cellForRowAtIndexPath code:
cell.body.text = user.message;
[cell.body sizeToFit];
The only solution I've found so far is double calling [table reloadData] but this is an ugly solution. Any way I can fix this?
Edit: Previous code was a summary, I'll show the whole code here as requested:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TwitterTweetCell *cell = [tableView dequeueReusableCellWithIdentifier:#"TwitterTweetCell"];
// Populate cell
TweetModelData *tweet = [self.twitterModelData.tweets objectAtIndex:[indexPath item]];
cell.tweetName.text = tweet.user;
cell.tweetChannel.text = tweet.userName;
cell.tweetBody.text = tweet.message;
[cell.tweetBody sizeToFit];
return cell;
}
Regarding cell size, everything is working ok. Depending on the size of the message each cell has a different size which was pre-calculated before.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ((TweetModelData *)[self.twitterModelData.tweets objectAtIndex:[indexPath item]]).tweetHeight + 30.0f;
}
I finally found it. Don't know the reason, but it seems disabling "Use autolayout" on my storyboard fixed it.
I'm guessing auto-layout was overwriting the layout changes I was applying so they had no effect until the next data reload.
ios Noob here. I have an iOS TableView which needs to have a few items in each row: A UILabel for asking a question, Yes button, No button, and a slider to answer "rate between 1 and 5". The slider won't actually show on every question only when the question deals with a rating.
What's the best way to accomplish adding all the "widgets" to the TableView row? Progmatically or through storyboards? Also, if I use storyboards, how would I go about hiding the rating bar and then showing it again when needed?
UPDATED WITH CODE SNIPPET
#property (strong,nonatomic) NSMutableArray *ObjQuestions;
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
OBJ_Question *q1 = [self.ObjQuestions objectAtIndex:indexPath.row];
cell.textLabel.text = q1.QuestionText;
// need to access second and third Label widgets from storyboard here
// as well as show/hide NSSlider
return cell;
}
You have to subclass UITableviewCell and add your custom items to the content view of the UITableViewCell. Use your custometableview cell in your UITableView datasource & delegate method. If you need more info than this, let me know and I can give you a sample code
If you use Storyboards you can create two types of cells, one with the slider, and one without. All you need to do then is to load the correct cell depending on your data for that row.
It's easier than trying to hide and show the slider.
I am using a UITableView with a custom UITableViewCell. The cell just has a label on it for now for testing.
The issue that I have is that when I use the following code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HZEventCell *eventCell = [tableView dequeueReusableCellWithIdentifier:HZ_EVENT_CELL_REUSE_IDENTIFIER];
EKEvent *event = [EKEvent eventWithEventStore:self.dataSource.eventStore];
event.title = #"Document re-write meeting";
eventCell.label.text = event.title;
NSLog(#"Event: %#", event.title);
return eventCell;
}
This causes my label to be offset when the app loads, hanging off the edge of the screen. If I pull the actual event data from my instance of the EKEventStore then the offset changes based on the event title. Some times the entire label is centered in the cell, other times the label is 50% off the left edge of the screen. If I print the contents of event.title via NSLog, there are no formatting issues that I can see.
When I use the following code.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HZEventCell *eventCell = [tableView dequeueReusableCellWithIdentifier:HZ_EVENT_CELL_REUSE_IDENTIFIER];
NSString *title = event.title; //self.data[indexPath.row];
eventCell.label.text = title;
return eventCell;
}
the label displays the text without any issues. It's not something that I am doing with the events in my data source, because the above code has me creating a new event, setting the title and assiging it to the cell's label, which still gives me an offset. It looks like cell.label.origin.x is equal to -25p. Anyone ever see this or know why this is happening? My sub-class of UITableViewCell has no code other than an outlet for the label in the header.
Note that I have this issue in iOS 6, I just happened to be doing this testing using the iOS 7 SDK when I took the screenshot.