Добавление просмотра таблицы в режиме прокрутки с отключенной прокруткой таблицы в Iphone - PullRequest
0 голосов
/ 11 октября 2011

У меня есть вид прокрутки с меткой, а также вид таблицы и кнопка.Я просто хочу прокрутить представление прокрутки, и представление таблицы должно отображать все содержимое, но представление таблицы не должно прокручиваться.Под столом у меня есть кнопка.Как установить рамку кнопки так, чтобы она находилась точно под таблицей?

Спасибо

Ответы [ 4 ]

0 голосов
/ 10 сентября 2012

Предполагается, что вы создали IBOutlets для scrollView, tableView и button и соответствующим образом подключили их.

Я считаю полезным вспомнить, что мы только портим значения y CGRect (origin.y & size.height) - значения x должны быть установлены в xib.

Я прокомментировал это, чтобы лучше проиллюстрировать свою точку зрения, обычно я комментировал только в случае необходимости

-(void)viewDidLoad {
[self.tableView setScrollEnabled:NO];

// Get the number of rows in your table, I use the method
// 'tableView:numberOfRowsInSection:' because I only have one section.

int numOfRows = [self.tableView numberOfRowsInSection:0];

// Get the height of your rows. You can use the magic 
// number 46 (44 without including the separator 
// between rows) for the height of your rows, but because
// I was using a custom cell, I had to declare an instance
// of that cell and exctract the height from 
// cell.frame.size.height (adding +2 to compensate for
// the separator). But for the purpose of this demonstration
// I'm going to stick with a magic number

int rowHeight = 46; //Eww, Magic numbers! :/

// Get a reference to the tableViews frame, and set the height
// of this frame to be the sum of all your rows

CGRect frame = self.tableView.frame;
frame.size.height = numOfRows * rowHeight;

// Now we have a frame with the exact size of our table,
// so set the 'tableView.frame' AND the 'tableView.contentSize'
// to that. (Because we want ALL rows visible as you
// disabled scrolling for the 'tableView')

self.tableView.frame = frame;
self.tableView.contentSize = frame.size;

// Now we want to set up the button beneath the table. 
// We still have the 'frame' variable, which gives us 
// the tableView's Y-origin and height. We just add these
// two together (with +20 for padding) to get the origin of the button

CGRect buttonFrame = self.button.frame;
buttonFrame.origin.y = frame.origin.y + frame.size.height + 20;
self.button.frame = buttonFrame;

// Finally, we want the `scrollView`'s `contentSize` to
// encompass this entire setup (+20 for padding again)

CGRect scrollFrame = self.scrollView.frame;
scrollFrame.size.height = buttonFrame.origin.y + buttonFrame.size.height = 20;
self.scrollView.contentSize = scrollFrame.size;
}
0 голосов
/ 11 октября 2011

Вы можете остановить прокрутку представления таблицы.Но вы не должны добавлять табличное представление внутри прокрутки.UITableView является подклассом UIScrollView, и добавление одного scrollView к другому создаст проблему.Я предлагаю вам удалить представление прокрутки и использовать только представление таблицы (поскольку само представление таблицы является просмотром прокрутки).

0 голосов
/ 05 марта 2012

Да, мы можем отключить прокрутку таблицы.Перейти к-> xib-> выбрать таблицу-> Перейти к 1-й вкладке-> отменить выбор прокрутки Включено.

Ответ на второй вопрос.

Поместите UiView в нижний колонтитул таблицы и затем поместитекнопка в том UIView вы хотите показать в нижней части.Он всегда будет отображаться внизу.

Если вы хотите программно разместить кнопку, используйте следующий метод в методе viewDidload.

     ///--------Table Footer is Set here

     UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 260, 44)];
     UIButton *adddays = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 260, 44)];
     [adddays setBackgroundImage:[UIImage imageNamed:@"abcd.png"] forState:UIControlStateNormal];
     [adddays addTarget:self action:@selector(buttonaction) forControlEvents:UIControlEventTouchDown];
     UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(75, 12, 250, 20)];
     [text setBackgroundColor:CLEAR_COLOR];
     [text setText:@"Title for your button"];
     [text setTextColor:XDARK_BLUE];
    text.font=[UIFont fontWithName:@"Arial-BoldMT" size:18.0f];

    [footer addSubview:adddays];
    [footer addSubview:text];
    [table setTableFooterView:footer];  
0 голосов
/ 11 октября 2011

Может быть, вы хотите установить YourTableView.userInteractionEnabled = NO?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...