Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UITableView滚动边界_Objective C_Uitableview - Fatal编程技术网

Objective c UITableView滚动边界

Objective c UITableView滚动边界,objective-c,uitableview,Objective C,Uitableview,我将数据填充到一个数组中,然后将该数组插入到UITableView中。然而,一旦屏幕被填满,新的单元格就不会出现,因为它们会被追加到底部。有没有办法让它在添加项目时自动滚动到底部?此外,滚动也可以工作,但并不理想。例如,要进入最后一个项目,用户必须滚动并按住该手势才能显示该项目。例如,MyUITableView在其视图中最多可容纳17个项目。17之后,用户可以滚动,但是他们将无法选择项目18,因为他们必须按住滚动手势。为了选择第18项,他们必须再添加10项 - (NSInteger)number

我将数据填充到一个数组中,然后将该数组插入到
UITableView
中。然而,一旦屏幕被填满,新的单元格就不会出现,因为它们会被追加到底部。有没有办法让它在添加项目时自动滚动到底部?此外,滚动也可以工作,但并不理想。例如,要进入最后一个项目,用户必须滚动并按住该手势才能显示该项目。例如,My
UITableView
在其视图中最多可容纳17个项目。17之后,用户可以滚动,但是他们将无法选择项目18,因为他们必须按住滚动手势。为了选择第18项,他们必须再添加10项

- (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.
    // Usually the number of items in your array (the one that holds your list)
    return [_items count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //Where we configure the cell in each row

    static NSString *CellIdentifier = @"trap";
    UITableViewCell *cell;

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell... setting the text of our cell's label
    cell.textLabel.text = [_items objectAtIndex:indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"test");
}

加载tableView时,您可以手动设置contentOffset,因为您这次可以获取tableViewContentSize。

加载tableView时,您可以手动设置contentOffset,因为您这次可以获取tableViewContentSize。

加载tableView时,您可以手动设置contentOffset,因为您这次可以获取tableViewContentSize。

加载tableView时,您可以手动设置contentOffset,因为您这次可以获取tableViewContentSize。

无法显示表的最后一项

问题很可能是tableview的高度大于 你可以选择屏幕大小。也可以是自动布局问题。尽量缩小tableview的高度

有没有办法让它在添加项目时自动滚动到底部

[self.items addObject:[NSString stringWithFormat:@"Trawl %d", count]];
[self.tableView reloadData];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:self.item.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES]

下面是我的整个测试控制器

@interface DPCalendarTestCreateEventViewController ()<UITableViewDelegate, UITableViewDataSource, DPCalendarTestOptionsCellDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *items;

@end

@implementation DPCalendarTestCreateEventViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.items = @[@"TEST", @"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST"].mutableCopy;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonSelected)];

    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    [self.view addSubview:self.tableView];
}

- (void) doneButtonSelected{
    [self.items addObject:[NSString stringWithFormat:@"Trawl %d", self.items.count]];
    [self.tableView reloadData];
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:self.items.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //Where we configure the cell in each row

    static NSString *CellIdentifier = @"trap";
    UITableViewCell *cell;

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell... setting the text of our cell's label
    cell.textLabel.text = [_items objectAtIndex:indexPath.row];
    return cell;
}

@end
@interface DPCalendarTestCreateEventViewController()
@属性(非原子,强)UITableView*tableView;
@属性(非原子,强)NSMutableArray*项;
@结束
@实现DPCalendarTestCreateEventViewController
-(无效)viewDidLoad
{
[超级视图下载];
自我项目=@[@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”]。可修改副本;
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:uiBarButtonSystemItem完成目标:自我操作:@selector(doneButtonSelected)];
self.tableView=[[UITableView alloc]initWithFrame:self.view.bounds样式:UITableView样式分组];
self.tableView.dataSource=self;
self.tableView.autoresizingMask=uiviewsautoresizingflexiblewhight | uiviewsautoresizingflexiblewidth;
[self.view addSubview:self.tableView];
}
-(无效)doneButtonSelected{
[self.items添加对象:[NSString stringWithFormat:@“拖网%d”,self.items.count];
[self.tableView重载数据];
[self.tableView ScrollToRowatineXpath:[NSIndexPath indexPathForItem:self.items.count-1第1节:0]atScrollPosition:UITableViewScrollPositionBottom:YES];
}
#pragma标记-UITableViewDataSource
-(NSInteger)表格视图中的节数:(UITableView*)表格视图{
//返回节数。
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
返回[_项目计数];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
//我们在其中配置每行中的单元格
静态NSString*CellIdentifier=@“陷阱”;
UITableViewCell*单元格;
cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];
}
//配置单元格…设置单元格标签的文本
cell.textlab.text=[\u items objectAtIndex:indexath.row];
返回单元;
}
@结束

您不能显示表格的最后一项

问题很可能是tableview的高度大于 你可以选择屏幕大小。也可以是自动布局问题。尽量缩小tableview的高度

有没有办法让它在添加项目时自动滚动到底部

[self.items addObject:[NSString stringWithFormat:@"Trawl %d", count]];
[self.tableView reloadData];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:self.item.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES]

下面是我的整个测试控制器

@interface DPCalendarTestCreateEventViewController ()<UITableViewDelegate, UITableViewDataSource, DPCalendarTestOptionsCellDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *items;

@end

@implementation DPCalendarTestCreateEventViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.items = @[@"TEST", @"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST",@"TEST"].mutableCopy;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonSelected)];

    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    [self.view addSubview:self.tableView];
}

- (void) doneButtonSelected{
    [self.items addObject:[NSString stringWithFormat:@"Trawl %d", self.items.count]];
    [self.tableView reloadData];
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:self.items.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //Where we configure the cell in each row

    static NSString *CellIdentifier = @"trap";
    UITableViewCell *cell;

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell... setting the text of our cell's label
    cell.textLabel.text = [_items objectAtIndex:indexPath.row];
    return cell;
}

@end
@interface DPCalendarTestCreateEventViewController()
@属性(非原子,强)UITableView*tableView;
@属性(非原子,强)NSMutableArray*项;
@结束
@实现DPCalendarTestCreateEventViewController
-(无效)viewDidLoad
{
[超级视图下载];
自我项目=@[@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”、@“测试”]。可修改副本;
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:uiBarButtonSystemItem完成目标:自我操作:@selector(doneButtonSelected)];
self.tableView=[[UITableView alloc]initWithFrame:self.view.bounds样式:UITableView样式分组];
self.tableView.dataSource=self;
self.tableView.autoresizingMask=uiviewsautoresizingflexiblewhight | uiviewsautoresizingflexiblewidth;
[self.view addSubview:self.tableView];
}
-(无效)doneButtonSelected{
[self.items添加对象:[NSString stringWithFormat:@“拖网%d”,self.items.count];
[self.tableView重载数据];
[self.tableView ScrollToRowatineXpath:[NSIndexPath indexPathForItem:self.items.count-1第1节:0]atScrollPosition:UITableViewScrollPositionBottom:YES];
}
#pragma标记-UITableViewDataSource
-(NSInteger)表格视图中的节数:(UITableView*)表格视图{
//返回节数。
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
返回[_项目计数];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
//我们在其中配置每行中的单元格
静态NSString*CellIdentifier=@“陷阱”;
UITableViewCell*单元格;
cell=[tableView出列器