पर अटक गया है, वर्तमान में मैं स्टोरीबोर्ड का उपयोग किए बिना कस्टम सेल के साथ एक साधारण UITableView बनाने की कोशिश कर रहा हूं।आईओएस 8 पर UITableView सेल चौड़ाई 320pt
मैं 6 सिम्युलेटर जहां तालिका दृश्य 375 की चौड़ाई है (जैसा कि होना चाहिए) iPhone पर एक मुद्दा हो रही है, लेकिन कोशिकाओं के अंदर संख्या 320 कहीं नहीं है 320.
की चौड़ाई हो रही है प्रोजेक्ट में पाया जा सकता है क्योंकि मैं इसे कड़ी मेहनत नहीं कर रहा हूं। जब मैं सेल का पृष्ठभूमि रंग सेट कर रहा हूं, तो यह 375 की पूरी चौड़ाई बढ़ाता है, लेकिन मुझे दाईं ओर एक छवि को संरेखित करने की आवश्यकता है, जो नीचे दी गई तस्वीर में दिखाए गए अनुसार 320 को केवल संरेखित करता है।
मुझे यकीन है कि अगर यह है क्योंकि मैं याद आ रही बाधाओं हूँ या अगर कोई एक बग है नहीं कर रहा हूँ। हर प्रकार की सहायता का स्वागत है, धन्यवाद!
कोड तालिका स्थापित करने के लिए:
- (TBMessageViewCell *)getMessageCellforTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"MessageCell";
TBMessageViewCell *cell = (TBMessageViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[TBMessageViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
[cell createSubviews];
}
// Set the new message and refresh
[cell setMessage:self.viewModel.messages[indexPath.row]];
[cell populateSubviews];
cell.backgroundColor = [UIColor blueColor];
NSLog(@"cell Width: %f", cell.contentView.frame.size.width);
return cell;
}
पूरा TBMessageViewCell:
@implementation TBMessageViewCell
const CGFloat MARGIN = 10.0f;
const CGFloat AVATAR_SIZE = 40.0f;
-(id)initWithStyle:(UITableViewCellStyle *)style reuseIdentifier:(NSString *)reuseIdentifier
{
if(self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]){
}
// Sets background and selected background color
self.backgroundColor = [UIColor clearColor];
UIView *selectionColor = [[UIView alloc] init];
selectionColor.backgroundColor = [UIColor clearColor];
self.selectedBackgroundView = selectionColor;
return self;
}
- (void)populateSubviews
{
// Set the message body
[self.messageBodyLabel setText:self.message.body];
[self.messageBodyLabel setTextAlignment:NSTextAlignmentRight];
CGRect bodyFrame = CGRectMake(MARGIN, MARGIN, self.frame.size.width - (AVATAR_SIZE + (MARGIN * 3)), self.frame.size.height);
// Calculates the expected frame size based on the font and dimensions of the label
// FLT_MAX simply means no constraint in height
CGSize maximumLabelSize = CGSizeMake(bodyFrame.size.width, FLT_MAX);
CGRect textRect = [self.message.body boundingRectWithSize:maximumLabelSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:self.messageBodyLabel.font}
context:nil];
bodyFrame.size.height = textRect.size.height;
// Setup the new avatar frame (Right aligned)
CGRect avatarFrame = CGRectMake(bodyFrame.size.width + (MARGIN * 2), MARGIN, AVATAR_SIZE, AVATAR_SIZE);
// Align to the LEFT side for current user's messages
if ([[TBConfig userID] isEqualToString:self.message.user.userID]) {
// Set avatar to left if it's me
avatarFrame.origin.x = MARGIN;
bodyFrame.origin.x = AVATAR_SIZE + (MARGIN * 2);
[self.messageBodyLabel setTextAlignment:NSTextAlignmentLeft];
}
self.avatar.frame = avatarFrame;
self.avatar.layer.cornerRadius = self.avatar.frame.size.width/2;
self.messageBodyLabel.frame = bodyFrame;
// Set the new cell height on the main Cell
CGFloat cellHeight = MAX(bodyFrame.size.height, self.frame.size.height) + MARGIN;
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, cellHeight);
// Set the new Profile avatar
if (![self.avatar.profileID isEqualToString:self.message.user.facebookID]) {
[self.avatar setProfileID:nil];
[self.avatar setProfileID:self.message.user.facebookID];
}
}
- (void)createSubviews
{
self.messageBodyLabel = [[UILabel alloc] init];
self.messageBodyLabel.textColor = [UIColor whiteColor];
self.messageBodyLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.messageBodyLabel.numberOfLines = 0;
[self addSubview:self.messageBodyLabel];
// Creates the avatar
self.avatar = [[FBProfilePictureView alloc] init];
[self.avatar setPictureCropping:FBProfilePictureCroppingSquare];
[self addSubview:self.avatar];
}
यदि आप स्टोरीबोर्ड में सेल्स का उपयोग नहीं कर रहे हैं, तो आप उन्हें कैसे बना रहे हैं? निब फ़ाइल? कोड? यदि कोड कोड – Paulw11