现在我正在制作一个 twitter 应用程序,我正在使用 IFTweetLabel。我创建了一个 TableViewCell 子类,但是当我运行它时,标签会出现。
这是.h:
#import <UIKit/UIKit.h>
#import "IFTweetLabel.h"
@interface twitterTextCell : UITableViewCell
@property (strong, nonatomic) IFTweetLabel *customtextLabel;
@end
这是实现:
#import "twitterTextCell.h"
@implementation twitterTextCell
@synthesize customtextLabel;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
customtextLabel.backgroundColor = [UIColor orangeColor];
self.customtextLabel.frame = CGRectMake(240, 60, 345, 109);
[self addSubview:customtextLabel];
NSLog(@"Custom Label Text: %@", customtextLabel.text);
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(UILabel *)textLabel
{
return nil;
}
这是 tableviewdelegate 的 cellforrow 中的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
twitterTextCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[twitterTextCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSDictionary *tweet = [self.timeLineData objectAtIndex:indexPath.row];
if ([tweet objectForKey:@"text"] != nil) {
NSString *allText = [[tweet objectForKey:@"text"] stringByDecodingHTMLEntities];
cell.customtextLabel.numberOfLines = 4;
cell.textLabel.numberOfLines = 4;
cell.customtextLabel.text = allText;
cell.textLabel.text = allText;
cell.customtextLabel.linksEnabled = YES;
NSDictionary *whoPostedTweet = [tweet objectForKey:@"user"];
cell.detailTextLabel.text = [whoPostedTweet objectForKey:@"name"];
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@", [whoPostedTweet objectForKey:@"profile_image_url"]]];
[cell.imageView setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
cell.backgroundColor = [UIColor clearColor];
[cell.imageView.layer setCornerRadius:7.0f];
[cell.imageView.layer setMasksToBounds:YES];
return cell;
} else {
[self getTwitterData];
NSLog(@"nil called(else) ");
return cell;
}
return cell;
}
毕竟这一切只显示图像和detailtextview。我删除了默认的文本视图,因为如果我没有正常显示文本,但它不是 IFTweetLabel。我有一个问题是如何重新定位detailtextabel,使其位于IFTweetLabel 下。任何事情都非常感谢,我在这两个问题上都需要帮助。