UIlabel with Custom cell not appear - ios

I'm confused !, it is not my first time to create Custom Cell but this time UILabel doesn't appear I don't know where is the problem ?
This the custom cell Cell.m
mainView = [[UIView alloc] initWithFrame:CGRectZero];
mainView.backgroundColor = [UIColor colorWithRed:249.0/255.0 green:249.0/255.0 blue:249.0/255.0 alpha:1.0];
profile = [[UIImageView alloc] initWithFrame:CGRectZero];
profile.layer.masksToBounds = YES;
profile.layer.cornerRadius = 22.5;
profile.layer.borderColor = [UIColor whiteColor].CGColor;
profile.layer.borderWidth = 1.0f;
profile.clipsToBounds = YES;
tweet_is = [[UILabel alloc] initWithFrame:CGRectZero];
tweet_is.font = [UIFont fontWithName:#"HelveticaNeue-Thin" size:20];
tweet_is.backgroundColor = [UIColor clearColor];
tweet_is.textColor = [UIColor blackColor];
[self.mainView addSubview:tweet_is];
[self.mainView addSubview:profile];
[self.contentView addSubview:self.mainView];
-(void)layoutSubviews {
[super layoutSubviews];
self.mainView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 10.0f);
self.profile.frame = CGRectMake(15, 15, 45, 45);
self.tweet_is.frame = CGRectMake(30, 30, 300.0f, 300.0f);
}
This is the tableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
Cell *cell = (Cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.tweet_is.text = #"Not approve";
return cell;
}

Change this line:
self.tweet_is.frame = CGRectMake(30, 30, 300.0f, 300.0f);
set it self.tweet_is.frame = CGRectMake(30, 30, 300.0f, 30.0f);
If your cell height is less than 300 (I think it is) then you can not see the text. Let me know if that helps.. :)

Related

UITableView not displaying correctly on iPad

On the iPhone, the tableview looks fine, but in the iPad (simulator ios10), this is how it's shown:
Check image here: http://welove.pt/img/ipadtrouble.png
Any idea why its displaying differently on iPhone/iPad?
Also, what's with that white corner by the search icon? why isn't it black?
ViewDidLoad:
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorColor = [UIColor colorWithRed:58/255.0 green:58/255.0 blue:58/255.0 alpha:1.0];
_tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
_tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[self.view addSubview:_tableView];
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
UIView *selectionColor = [[UIView alloc] init];
selectionColor.backgroundColor = [UIColor colorWithRed:(54/255.0) green:(54/255.0) blue:(54/255.0) alpha:1];
cell.selectedBackgroundView = selectionColor;
cell.backgroundColor = [UIColor colorWithRed:(28/255.0) green:(28/255.0) blue:(28/255.0) alpha:1];
cell.textLabel.textColor = [UIColor whiteColor];
}
if (indexPath.section == 0) {
cell.imageView.image = [[UIImage imageNamed:#"defineLocation.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UILabel *ttitle = [[UILabel alloc] initWithFrame:CGRectMake(46, 12, 320, 20)];
ttitle.font = [UIFont systemFontOfSize:17];
ttitle.textColor = [UIColor colorWithRed:(115/255.0) green:(229/255.0) blue:(69/255.0) alpha:1.0];
[ttitle setText:NSLocalizedString(#"current_location", nil)];
[cell.contentView addSubview:ttitle];
} else {
cell.textLabel.text = [[_recentSearchData objectAtIndex:indexPath.row] objectForKey:#"recentTitle"];
}
return cell;
}
Thank you for your help.
Subclassing the UITableViewCell solved the alignment issues.
Regarding that white arrow when the view is popping over on the iPad, i managed to change it's color with:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.popoverPresentationController.backgroundColor = [UIColor colorWithRed:(23/255.0) green:(23/255.0) blue:(23/255.0) alpha:1.0];
}
this viewWillAppear belongs to the UITableViewController that is shown in the popover.
Thanks for your suggestions

UITableview overwriting on olddata

hi im creating chat example and if user add send button adding new object in my arrray and reload data but its overwrite old table.
its my array :
arr1 = [[NSMutableArray alloc] initWithObjects:#"Whats up today ? ", #"Hello.", nil];
Here my source :
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simleTableIdentifier = #"TeamCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"TeamCell"];
}
cell.backgroundColor = [UIColor clearColor];
tableView.scrollEnabled = YES;
UIImageView *myRect = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, 10, 12)];
myRect.image = [UIImage imageNamed:#"tri.png"];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"jj.jpg"]];
UILabel *label = [[UILabel alloc] init];
label.text = [arr1 objectAtIndex:indexPath.row];
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.font =[UIFont systemFontOfSize:14.0];
label.text = [arr1 objectAtIndex: indexPath.row];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.frame = CGRectMake(40, 40, 210, 80);
[label sizeToFit];
UIImageView *imgim = [[UIImageView alloc] initWithFrame:CGRectMake(30, 10, label.frame.size.width+20, label.frame.size.height+20)];
imgim.image = [UIImage imageNamed:#"bg.png"];
CGRect myRectANGLE = CGRectMake(imgim.frame.origin.x+10,imgim.frame.origin.y+10, label.frame.size.width, label.frame.size.height);
[label setFrame:myRectANGLE];
CALayer *addRadius = [imgim layer];
[addRadius setMasksToBounds:YES];
[addRadius setCornerRadius:5.0];
[self.MyTableView setSeparatorColor:[UIColor clearColor]];
[self.MyTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
self.MyTableView.transform = CGAffineTransformMakeScale(1, -1); //in viewDidLoad
cell.transform = CGAffineTransformMakeScale(1, -1);//in tableView:cellForRowAtIndexPath:
[[cell contentView] addSubview:myRect];
[[cell contentView] addSubview:imgim];
[[cell contentView] addSubview:label];
return cell;
}
İf click send button i reload data but its overwite on old-data look like my photo :
-(IBAction)btnTap:(UIButton *)sender {
[arr1 insertObject:Textify.text atIndex:0];
NSLog(#"%i", arr1.count);
[MyTableView reloadData];
}
Try clearing the cell's contentView subview, and then add the new subviews.
Here's a block of code for removing the subviews, taken from this post.
if ([cell.contentView subviews]){
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
}
UITableViewCell will be reused while reload, you should not create subviews again to add on cell.contentView.Try to use code below
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"TeamCell"];
UILabel *label = [[UILabel alloc] initWithFrame:someFrame];
label.tag = 1000;
[cell.contentView addSubview:label];
}
UILabel *label = [cell.contentView viewWithTag:1000];
label.text = #"something";

UITableView's viewForHeaderInSection method: accessing a cell's visual properties

I am defining a header row for my UITableView using the viewForHeaderInSection delegate method, and I wanted to get the X coodinate from the first row to position some labels, because I'm moving about the labels in the row constantly and would like to define those coordinates in the storyboard. But it's not working: the X coordinate is always 0. Here is the attempt:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
float x = tableView.frame.origin.x;
float y = tableView.frame.origin.y;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y - 22, tableView.bounds.size.width, 12)];
view.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
view.userInteractionEnabled = YES;
view.backgroundColor = [UIColor lightGrayColor];
LogCell *cell = (LogCell *)[tableView cellForRowAtIndexPath:0];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(cell.label_DATE.frame.origin.x, 0, 65, 22)];
dateLabel.backgroundColor = [UIColor clearColor];
dateLabel.font = [UIFont systemFontOfSize:12.0];
dateLabel.text = #"DATE";
UILabel *locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(cell.label_LOC.frame.origin.x, 0, 65, 22)];
locationLabel.backgroundColor = [UIColor clearColor];
locationLabel.font = [UIFont systemFontOfSize:12.0];
locationLabel.text = #"LOC";
[view addSubview:dateLabel];
[view addSubview:locationLabel];
return view;
}
Is there some way to properly get a row from the UITableView to ascertain the X/Y coordinates of the cell's labels?
This line:
LogCell *cell = (LogCell *)[tableView cellForRowAtIndexPath:0];
is the same as:
LogCell *cell = (LogCell *)[tableView cellForRowAtIndexPath:nil];
You aren't passing in an index path:
Try this:
LogCell *cell = (LogCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]];

UILabel -- WordWrap -- Frame Issue

A UILabel in my App is behaving unusually and I'm wondering if anyone has any ideas or suggestions on how to resolve it.
1.First I set the frames of the labels which will both appear inside the cell of a tableView.
CGRect CellFrame = CGRectMake(0, 0, 300, 75);
CGRect Label1Frame = CGRectMake(10, 5, 290, 20);
CGRect Label2Frame = CGRectMake(0, 20, 290, 50);
UILabel *lblTemp;
UITableViewCell *cell = [[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier];
Then I set the properties of labels
1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
lblTemp.font = [UIFont fontWithName:#"Helvetica" size:12.0];
lblTemp.textColor = [UIColor blackColor];
lblTemp.lineBreakMode = UILineBreakModeWordWrap;
lblTemp.numberOfLines = 0;
[cell.contentView addSubview:lblTemp];
//Initialize Label with tag 2.
lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
lblTemp.tag = 2;
lblTemp.font = [UIFont fontWithName:#"Helvetica" size:10];
lblTemp.textColor = [UIColor lightGrayColor];
lblTemp.lineBreakMode = UILineBreakModeWordWrap;
lblTemp.numberOfLines = 0;
[cell.contentView addSubview:lblTemp];
return cell;
3.Then I setup the contents of the cell
//set up the cell
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
CaseFeed *aCaseFeed = [[CaseFeed alloc] init];
aCaseFeed = [CaseFeedbook objectAtIndex:indexPath.row];
lblTemp1.text = [NSString stringWithFormat:#"%#", aCaseFeed.title];
lblTemp2.text = [NSString stringWithFormat:#"%#", aCaseFeed.description];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
PROBLEM: The contents of lblTemp2 (the second label in the cell) will span 2 or more lines. During runtime, when the text of lblTemp2 is populated, the first two lines appear perfectly, however the third line starts outside the left side of the frame.
Any ideas on how to resolve this? Why is this happening?
Use the following code to setup your cell of a tableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
else
{
for (id v in cell.contentView.subviews)
{
UIView *realV = (UIView *) v;
[realV removeFromSuperview];
}
}
CGRect CellFrame = CGRectMake(0, 0, 300, 75);
CGRect Label1Frame = CGRectMake(10, 5, 290, 20);
CGRect Label2Frame = CGRectMake(0, 20, 290, 50);
UILabel *label1 = [[UILabel alloc] init];
label1.frame = Label1Frame;
label1.tag = 1;
label1.font = [UIFont fontWithName:#"Helvetica" size:12.0];
label1.textColor = [UIColor blackColor];
label1.lineBreakMode = UILineBreakModeWordWrap;
label1.numberOfLines = 0;
[cell.contentView addSubview:label1];
UILabel *label2 = [[UILabel alloc] init];
label2.frame = Label2Frame;
label2.tag = 2;
label2.font = [UIFont fontWithName:#"Helvetica" size:10.0];
label2.textColor = [UIColor lightGrayColor];
label2.lineBreakMode = UILineBreakModeWordWrap;
label2.numberOfLines = 0;
[cell.contentView addSubview:label2];
CaseFeed *aCaseFeed = [[CaseFeed alloc] init];
aCaseFeed = [CaseFeedbook objectAtIndex:indexPath.row];
label0.text = [NSString stringWithFormat:#"%#", aCaseFeed.title];
label1.text = [NSString stringWithFormat:#"%#", aCaseFeed.description];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
Hope this helps

Label in UITableCellView.contentView showing two times when using autoresizing

I'm using Grouped UITableView and add UITableViewCells two UILabel's and adding them to the contentView of the cell. I am also implementing edit mode in my app on this UITableView.
I use the
lblDetail.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; in order to decrease width of the text so the delete red button showing in edit mode will not cover my text.
Now what I see is when I scroll my table not in edit mode the labels show two times as if it is in in edit mode and out of edit mode at the same time.
This is the code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
CGRect DetailLabelFrame = CGRectMake(52, 25, 200, 35);
CGRect TitleLabelFrame = CGRectMake(52, 5, 200, 25);
lblDetail = [[UILabel alloc]init];
lblTitle = [[UILabel alloc]init];
lblDetail.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblTitle.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblDetail.frame = DetailLabelFrame;
lblDetail.lineBreakMode = UILineBreakModeWordWrap;
lblDetail.backgroundColor = [UIColor clearColor];
lblDetail.numberOfLines = 2;
lblTitle.frame = TitleLabelFrame;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.frame = TitleLabelFrame;
[lblDetail setFont:[UIFont fontWithName:#"Arial" size:14]];
[lblTitle setFont:[UIFont fontWithName:#"Arial-BoldMT" size:15]];
lblDetail.textAlignment = UITextAlignmentRight;
lblTitle.textAlignment = UITextAlignmentRight;
lblTitle.text = #"054-9700583";
lblDetail.text = #"שאלה:במה אפשר לעזור לך?";
[cell.contentView addSubview:lblDetail];
[cell.contentView addSubview:lblTitle];
cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0;
cell.imageView.image = [UIImage imageNamed:#"girl.png"];
[lblDetail release];
[lblTitle release];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
CGRect DetailLabelFrame = CGRectMake(52, 25, 200, 35);
CGRect TitleLabelFrame = CGRectMake(52, 5, 200, 25);
lblDetail = [[UILabel alloc]init];
lblTitle = [[UILabel alloc]init];
lblDetail.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblTitle.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblDetail.frame = DetailLabelFrame;
lblDetail.lineBreakMode = UILineBreakModeWordWrap;
lblDetail.backgroundColor = [UIColor clearColor];
lblDetail.numberOfLines = 2;
lblTitle.frame = TitleLabelFrame;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.frame = TitleLabelFrame;
[lblDetail setFont:[UIFont fontWithName:#"Arial" size:14]];
[lblTitle setFont:[UIFont fontWithName:#"Arial-BoldMT" size:15]];
lblDetail.textAlignment = UITextAlignmentRight;
lblTitle.textAlignment = UITextAlignmentRight;
[cell.contentView addSubview:lblDetail];
[cell.contentView addSubview:lblTitle];
lblDetail.tag = 10;
lblTitle.tag = 11;
}
lblDetail = (UILabel*)[cell.contentView viewWithTag:10];
lblTitle = (UILabel*)[cell.contentView viewWithTag:11];
lblTitle.text = #"054-9700583";
lblDetail.text = #"שאלה:במה אפשר לעזור לך?";
cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0;
cell.imageView.image = [UIImage imageNamed:#"girl.png"];
[lblDetail release];
[lblTitle release];
return cell;
}
Your cell contents was overlapping may be it will help you.Still now if you face same problem the knock me without any hesitation.
If this is only happening when you're scrolling it may be because when a cell is being reused it's creating a new set of labels in addition to what's already in the reused cell.
What you can try to do is move these two lines into your if (cell == nil ) block:
lblDetail = [[UILabel alloc]init];
lblTitle = [[UILabel alloc]init];
That way when a cell is being reused it'll continue to use the existing lblDetail and lblTitle instead of creating a new one.

Resources