ios – UITableView setSeparatorInset无法正常工作

ios – UITableView setSeparatorInset无法正常工作,第1张

概述我试图在UITableView中为分隔符设置自定义插件.这是我的viewDidLoad代码 - (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerClass:[ChatTableCell class] forCellReuseIdentifier:@"ChatCell"]; [self.tabl 我试图在UItableVIEw中为分隔符设置自定义插件.这是我的vIEwDIDLoad代码

- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    [self.tableVIEw registerClass:[ChattableCell class] forCellReuseIDentifIEr:@"ChatCell"];    [self.tableVIEw setSeparatorInset:UIEdgeInsetsMake(0,65,0)];}

单元格分隔符插图无法正常工作,如图所示.它适用于某些细胞而不适用于其他细胞.我在这做错了什么?

这是我的vIEwcontroller.m文件的样子

#import "ChatListVIEwController.h"@interface ChatListVIEwController ()@end@implementation ChatListVIEwController- (ID)initWithStyle:(UItableVIEwStyle)style {    //self = [super initWithStyle:style];    self = [super initWithStyle:UItableVIEwStylePlain];    if (self) {        self.parseClassname = kChatRoomClassKey;        self.paginationEnabled = YES;        self.pullToRefreshEnabled = YES;        self.objectsPerPage = 25;        //[self.tableVIEw setSeparatorInset:UIEdgeInsetsMake(0,0)];    }    return self;}- (PFquery *)queryFortable {    if (![PFUser currentUser]) {        PFquery *query = [PFquery queryWithClassname:self.parseClassname];        [query setlimit:0];        return query;    }    PFquery *query = [PFquery queryWithClassname:self.parseClassname];    [query whereKey:kChatRoomUsersKey equalTo:[PFUser currentUser]];    [query includeKey:kChatRoomUsersKey];    [query orderByDescending:@"updatedAt"];    [query setCachePolicy:kPFCachePolicyCacheThenNetwork];    // If no objects are loaded in memory,we look to the cache first to fill the table    // and then subsequently do a query against the network.    //    // If there is no network connection,we will hit the cache first.    if (self.objects.count == 0 || ![[UIApplication sharedApplication].delegate performSelector:@selector(isParseReachable)]) {        [query setCachePolicy:kPFCachePolicyCacheThenNetwork];    }    return query;}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {    static Nsstring *CellIDentifIEr = @"ChatCell";    ChattableCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr];    if (cell == nil) {        cell = [[ChattableCell alloc] initWithStyle:UItableVIEwCellStyleSubTitle reuseIDentifIEr:CellIDentifIEr];        [cell setAccessoryType:UItableVIEwCellAccessorydisclosureIndicator];        [cell setSelectionStyle:UItableVIEwCellSelectionStyleGray];    }    cell.selectionStyle = UItableVIEwCellSelectionStyleNone;    NSArray *users = [object objectForKey:kChatRoomUsersKey];    PFUser *cellUser = (PFUser *)[users objectAtIndex:0];    if ([cellUser.objectID isEqualToString:[PFUser currentUser].objectID]) {        cellUser = [users objectAtIndex:1];        NSLog(@"%@",cellUser);    }    cell.textLabel.Font = [UIFont FontWithname:kDefaultFontKey size:17.0];    cell.detailTextLabel.Font = [UIFont FontWithname:kDefaultFontlightKey size:14];    if ([cellUser isEqual:[NSNull null]]) {        cell.username.text = @"SelfIE User";        cell.textLabel.Font = [UIFont FontWithname:kDefaultFontKey size:17.0];        cell.latestText.text = [object objectForKey:kChatRoomLatestTextKey];        cell.detailTextLabel.Font = [UIFont FontWithname:kDefaultFontKey size:10.0];        [cell.avatarImageVIEw.profileImageVIEw setimage:[UIImage imagenamed:@"AvatarPlaceholder.png"]];    }    else {        cell.username.text = cellUser.username;        cell.textLabel.Font = [UIFont FontWithname:kDefaultFontKey size:17.0];        cell.latestText.text = [object objectForKey:kChatRoomLatestTextKey];        cell.detailTextLabel.Font = [UIFont FontWithname:kDefaultFontKey size:10.0];        if ([[cellUser fetchIfNeeded] objectForKey:kPAPUserProfilePicSmallKey] == nil) {            [cell.avatarImageVIEw.profileImageVIEw setimage:[UIImage imagenamed:@"AvatarPlaceholder.png"]];        }        else            [cell.avatarImageVIEw setfile:[cellUser objectForKey:kPAPUserProfilePicSmallKey]];    }    return cell;}- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath {    return 70.0f;}-(voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath {    PFObject *chatRoomObject = [self.objects objectAtIndex:indexPath.row];    if ([[chatRoomObject objectForKey:kChatRoomreadKey] isEqual:@NO]) {        [chatRoomObject setobject:@YES forKey:kChatRoomreadKey];        [chatRoomObject saveEventually];        UITabbarItem *tabbarItem = [[self.tabbarController.vIEwControllers objectAtIndex:PAPFrIEndsTabbarItemIndex] tabbarItem];        Nsstring *currentBadgeValue = tabbarItem.badgeValue;        if (currentBadgeValue && currentBadgeValue.length > 1) {            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];            NSNumber *badgeValue = [numberFormatter numberFromString:currentBadgeValue];            NSNumber *newBadgeValue = [NSNumber numberWithInt:[badgeValue intValue] - 1];            tabbarItem.badgeValue = [numberFormatter stringFromNumber:newBadgeValue];        } else {            tabbarItem.badgeValue = @"";        }    }    ChatVIEwController *convoVC = [[ChatVIEwController alloc] init];    NSArray *users = [[self.objects objectAtIndex:indexPath.row] objectForKey:kChatRoomUsersKey];    PFUser *cellUser = (PFUser *)[users objectAtIndex:0];    if ([cellUser.objectID isEqualToString:[PFUser currentUser].objectID]) {        cellUser = [users objectAtIndex:1];    }    [convoVC setUser:cellUser];    [convoVC setChatRoom:[self.objects objectAtIndex:indexPath.row]];    [self.navigationController pushVIEwController:convoVC animated:YES];}- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    [self.tableVIEw registerClass:[ChattableCell class] forCellReuseIDentifIEr:@"ChatCell"];    [self.tableVIEw setSeparatorInset:UIEdgeInsetsMake(0,0)];        [self.navigationController.navigationbar setbarStyle:UIbarStyleBlack];        [self.navigationItem setTitle:@"Chat"];        //Change Back button text        UIbarbuttonItem *backbutton = [[UIbarbuttonItem alloc]                                       initWithTitle: @""                                       style: UIbarbuttonItemStylebordered                                       target: nil action: nil];        [self.navigationItem setBackbarbuttonItem: backbutton];        [self.navigationController setDelegate:self];}-(voID)vIEwDIDAppear:(BOol)animated {    [self loadobjects];    //Google Analytics screen tracking    ID tracker = [[GAI sharedInstance] defaultTracker];    [tracker set:kGAIScreenname           value:@"Chat"];    [tracker send:[[GAIDictionaryBuilder createScreenVIEw] build]];}-(voID)vIEwWillAppear:(BOol)animated {    [Flurry logEvent:@"VIEwed Chat" timed:YES];}-(voID)vIEwWilldisappear:(BOol)animated {    [Flurry endTimedEvent:@"VIEwed Chat" withParameters:nil];}@end
解决方法 在我的所有解决方法之后,现在已经在ios 7和8中进行了测试.

-(voID)vIEwDIDLayoutSubvIEws{  [customtablevIEw setSeparatorInset:UIEdgeInsetsZero];}-(voID)tableVIEw:(UItableVIEw *)tableVIEw willdisplayCell:(customCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{if ([tableVIEw respondsToSelector:@selector(setSeparatorInset:)]){    [tableVIEw setSeparatorInset:UIEdgeInsetsZero];}if ([tableVIEw respondsToSelector:@selector(setLayoutmargins:)]) {    [tableVIEw setLayoutmargins:UIEdgeInsetsZero]; // ios 8 newly added}if ([cell respondsToSelector:@selector(setLayoutmargins:)]) {    [cell setLayoutmargins:UIEdgeInsetsZero];}}
总结

以上是内存溢出为你收集整理的ios – UITableView setSeparatorInset无法正常工作全部内容,希望文章能够帮你解决ios – UITableView setSeparatorInset无法正常工作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1012295.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存