2015-11-20 115 views
0

我正在用两个NSArrays创建一个简单的tableView。第一个数组包含标题,第二个数组包含图像名称。一切工作正常。但是行分隔符在tableview中的图像之后会出现一些空格(参见第一张截图),而它应该没有空格(如第二张截图)。桌面图像显示不正常 - iOS 8 iPhone应用程序目标C

First Screenshot

Second screenshot

我尝试了不同的方法,但得到同样的问题(测试的iOS 8设备上)。

我在做什么错?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

// Return the number of sections. 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

// Return the number of rows in the section. 
return [dataSourceArray count]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

// "Cell" is the default cell identifier in a new Master-Detail Project 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 


    cell.textLabel.text = [dataSourceArray objectAtIndex:indexPath.row]; 

//get UIImage image Names from imageArray 
cell.imageView.image=[UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]]; 



return cell; 
} 
+0

也许这可以帮助你http://stackoverflow.com/questions/19103155/ios7-tableview-cell-imageview-extra-padding – ZHZ

+0

感谢。我的问题是通过添加自定义子视图解决的。 –

回答

0

我看不到你的形象.. 也许你没有使用限制或您的电池是小,你需要设置单元格的高度,以查看图像。

+0

在第一张截图中,绿色正方形是我的图像(我正在使用的示例图像)。大小是44x44,tableview单元格的高度也是44. –

+0

对不起,我看不到图像..你用过 cell.imageView.image = [UIImage imageNamed:@“”]; –

+0

是的,cell.imageView.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]]; imageArray包含imageNames –

0

尝试使用NSDictionary中

NSMutableArray *item; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

self.item = [NSMutableArray array]; 

NSDictionary *item1 = @{@"dicNameItem":@"NameItem",@"dicImageItem":@"ImageItem"}; 
[self.arrayScreen addObject:item1]; 

} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [self.arrayScreen count]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellScreen" forIndexPath:indexPath]; 

    NSDictionary *dicName = [self.arrayScreen objectAtIndex:indexPath.row]; 
    cell.textLabel.text = [dicName objectForKey:@"dicNameItem"]; 
    cell.imageView.image = [UIImage imageNamed:[dicName objectForKey:@"dicImageItem"]]; 

    return cell; 

} 
相关问题