Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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
Ios 如何将项目添加到侧菜单栏?_Ios_Xcode6 - Fatal编程技术网

Ios 如何将项目添加到侧菜单栏?

Ios 如何将项目添加到侧菜单栏?,ios,xcode6,Ios,Xcode6,我正在制作我的第一个应用程序。我的应用程序将有一个侧面弹出菜单。我已经用UITableView实现了滑动菜单部分。现在我想用文本和旁边的图像填充侧菜单,当点击一个时,我想按下另一个视图控制器。最好的方法是什么?谢谢正如用户132490所说,您可能想在tableView中添加行。这里有一个教程:。它适用于Xcode 5,但仍然可以工作。通过添加表数据和下面的内容,您可能会发现它很有用。事实上,在总结之前,本教程将教您在每个单元格的文本旁边添加缩略图 祝你好运 如果要为表创建图像和文本,必须创建UI

我正在制作我的第一个应用程序。我的应用程序将有一个侧面弹出菜单。我已经用UITableView实现了滑动菜单部分。现在我想用文本和旁边的图像填充侧菜单,当点击一个时,我想按下另一个视图控制器。最好的方法是什么?谢谢

正如用户132490所说,您可能想在tableView中添加行。这里有一个教程:。它适用于Xcode 5,但仍然可以工作。通过添加表数据和下面的内容,您可能会发现它很有用。事实上,在总结之前,本教程将教您在每个单元格的文本旁边添加缩略图


祝你好运

如果要为表创建图像和文本,必须创建UITableViewCell子类并声明图像视图和标签。图像视图和标签必须在IB中创建,创建一个原型单元并在那里添加图像视图和标签

完成后,必须有一个表内容数组。是这样的:

#pragma mark Table View delegate methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return  [menuArray count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    //return row height
    return 32;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier =@"Cell";

    //assign TableCell.h to access custom properties
    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    //get dictionary from menuArray
    NSDictionary * dict = [self.menuArray objectAtIndex:indexPath.row];

    UIImage *imageIcon = [UIImage imageNamed:[dict objectForKey:@"image"]];
    //set image
    [cell.img setImage:imageIcon];
    //set the label text
    cell.label.text = [dict objectForKey:@"desc"];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //research more about pushing another view controller.

    //if chosen was option1
    if (indexPath.row == 0) 
    {
        NSLog(@"option1");
    }

    //if chosen was option2
    if (indexPath.row == 1) 
    {
        NSLog(@"option2");
    }

    //if chosen was option3
    if (indexPath.row == 2) 
    {
        NSLog(@"option3");
    }

    // if chosen was option4
    if(indexPath.row == 3)
    {
        NSLog(@"option4");
    }

    // if chosen is option5
    if(indexPath.row == 4)
    {
        NSLog(@"option5");
    }
}
在@interface中:

在您的viewDidLoad中:

然后必须有如下表视图委托方法:

#pragma mark Table View delegate methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return  [menuArray count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    //return row height
    return 32;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier =@"Cell";

    //assign TableCell.h to access custom properties
    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    //get dictionary from menuArray
    NSDictionary * dict = [self.menuArray objectAtIndex:indexPath.row];

    UIImage *imageIcon = [UIImage imageNamed:[dict objectForKey:@"image"]];
    //set image
    [cell.img setImage:imageIcon];
    //set the label text
    cell.label.text = [dict objectForKey:@"desc"];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //research more about pushing another view controller.

    //if chosen was option1
    if (indexPath.row == 0) 
    {
        NSLog(@"option1");
    }

    //if chosen was option2
    if (indexPath.row == 1) 
    {
        NSLog(@"option2");
    }

    //if chosen was option3
    if (indexPath.row == 2) 
    {
        NSLog(@"option3");
    }

    // if chosen was option4
    if(indexPath.row == 3)
    {
        NSLog(@"option4");
    }

    // if chosen is option5
    if(indexPath.row == 4)
    {
        NSLog(@"option5");
    }
}
在推广到其他视图控制器时,请尝试进行更多的研究,因为这需要更多的解释。请尝试以下链接:

但是使用这些代码,您必须能够填充表,并且当您选择一个单元格时,将有一个日志。希望这有帮助:

可能重复的
#pragma mark Table View delegate methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return  [menuArray count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    //return row height
    return 32;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier =@"Cell";

    //assign TableCell.h to access custom properties
    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    //get dictionary from menuArray
    NSDictionary * dict = [self.menuArray objectAtIndex:indexPath.row];

    UIImage *imageIcon = [UIImage imageNamed:[dict objectForKey:@"image"]];
    //set image
    [cell.img setImage:imageIcon];
    //set the label text
    cell.label.text = [dict objectForKey:@"desc"];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //research more about pushing another view controller.

    //if chosen was option1
    if (indexPath.row == 0) 
    {
        NSLog(@"option1");
    }

    //if chosen was option2
    if (indexPath.row == 1) 
    {
        NSLog(@"option2");
    }

    //if chosen was option3
    if (indexPath.row == 2) 
    {
        NSLog(@"option3");
    }

    // if chosen was option4
    if(indexPath.row == 3)
    {
        NSLog(@"option4");
    }

    // if chosen is option5
    if(indexPath.row == 4)
    {
        NSLog(@"option5");
    }
}