Я бы порекомендовал вам попробовать для этого использовать UIScrollView вместо UITableView.
Каждый элемент в вашем меню может быть UIImageView или UIButton, который вы добавляете как подпредставления к вашему UIScrollView.
Следующий код может быть вставлен в viewDidLoad
внутри вашего контроллера представления и предполагает, что вы настроили UISCrollView в построителе интерфейса, в противном случае вам нужно будет выделить представление прокрутки внутри viewDidLoad
.
Код добавит переменное количество пунктов меню в UIScrollView с двумя столбцами.Чтобы справиться с пользовательским вводом, вы можете сделать все элементы меню UIButtons, которые вызывают связанные методы IBAction, или в этом случае menuItems являются вашими представлениями, поэтому вы можете определить, к какому пункту меню пользователь прикасается, глядя на местоположение касания пользователя в пределах прокруткипросмотреть, а затем выполнить соответствующие действия, основанные на этом.
UIImageView *menuItem = nil;
//The x and y view location coordinates for your menu items
int x = 0, y = 0;
//The number of items you want in your menu
int numOfItemsToAdd = 10;
//The height and width of your menu items
int menuItemHeight = 50, menuItemWidth = 50;
//The content seize needs to refelect the number of menu items that will be added
//The hieght of the ocnten size is calclutated by multiplying the menu item height by the number of
//menu items devided by the number of menu items that fit across in the width of the view.
[scrollView setContentSize:CGSizeMake(320, menuItemHeight*numOfItemsToAdd];
for(int i=0; i<numOfItemsToAdd; i++){
if(i%2 == 0){//% the number of columns you want in your menu
x = 0;
if(i!=0)
y += menuItemHeight;
}else{
x = menuItemWidth;
}
menuItem = [[UIImageView alloc] initWithFrame: CGRectMake(x, y, menuItemWidth, menuItemHeight)];
//set the center of the menu item in the scroll superviews coordinate system
menuItem.center = CGPointMake(x, y);
//Add the name of the image you want for the menu item
//These strings could be stored in an array and retrieved in order
menuItem.image = [UIImage imageNamed:@"MyImage"];
//Finaly add the menu item to the scorll view
[scrollView addSubview:menuItem];
}