Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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 如何使用loop in仅显示行中的3个按钮和列中的一个按钮_Ios_Objective C_Iphone - Fatal编程技术网

Ios 如何使用loop in仅显示行中的3个按钮和列中的一个按钮

Ios 如何使用loop in仅显示行中的3个按钮和列中的一个按钮,ios,objective-c,iphone,Ios,Objective C,Iphone,我想在行中显示3个按钮,在列中只显示一个按钮。我已经这样做了,但一行中应该只有3个按钮。如何以适当的方式进行管理。我只想以矩阵形式动态显示按钮。这个过程的正确循环是什么。请解决这个问题 //这是我的密码 // DPSGalleryViewController.m // DPSApp // // Created by EDUNEXT on 18/05/15. // Copyright (c) 2015 Edunext. All rights reserved. // #import "D

我想在行中显示3个按钮,在列中只显示一个按钮。我已经这样做了,但一行中应该只有3个按钮。如何以适当的方式进行管理。我只想以矩阵形式动态显示按钮。这个过程的正确循环是什么。请解决这个问题

//这是我的密码

//  DPSGalleryViewController.m
//  DPSApp
//
//  Created by EDUNEXT on 18/05/15.
//  Copyright (c) 2015 Edunext. All rights reserved.
//

#import "DPSGalleryViewController.h"
#import "DPSAppParser.h"
#import "DPSAppService.h"
#import "SharedPreferenceUtil.h"
#import "DPSGallery1ViewController.h"
#import "UIImageView+WebCache.h"
@interface DPSGalleryViewController ()
{
    NSMutableArray *imagearray;
    UIImageView *groupimageView;
  //  NSMutableArray *array;
   // UIButton *buttons;
    NSString *filepath1;
    }


@end

@implementation DPSGalleryViewController
@synthesize sv;
-(IBAction)firstview:(id)sender
{


    UIButton *aButton = [[UIButton alloc]init];//[[UIButton buttonWithType:UIButtonTypeCustom]initWithFrame:CGRectMake(120, 60, 80, 60)];
    aButton.backgroundColor=[UIColor clearColor];
    [self.view addSubview:aButton];
    DPSGallery1ViewController *galleryViewController =[self.storyboard instantiateViewControllerWithIdentifier:@"gallery1view"];
    [self.navigationController pushViewController:galleryViewController animated:YES];


}


- (void)viewDidLoad
{
    //set frame
    sv.frame =CGRectMake(0, 0, 320, 480);
    // set content size
    [sv setContentSize:CGSizeMake(320, 1000)];
    [super viewDidLoad];

    // Do any additional setup after loading the view.

    NSInteger intTagNumber  = 0;
    NSInteger intLeftMargin = 10; // horizontal offset from the edge of the screen
    NSInteger intTopMargin  = 20; // vertical offset from the edge of the screen
    NSInteger intXSpacing   = 85; // number of pixels between the button origins (horizontally)
    NSInteger intYSpacing   = 79; // number of pixels between the button origins (vertically)
    NSInteger intXTile;
    NSInteger intYTile;
    int k =1;

       for (int y = 1; y <1+k; y++)
    {
        for (int x = y; x <=4-k; x++)
        {

            intXTile = (x * intXSpacing) + intLeftMargin;
            intYTile = (y * intYSpacing) + intTopMargin;

            // create a value button, text, or image
            buttons[x][y] = [[UIButton alloc] initWithFrame:CGRectMake(intXTile, intYTile, 58, 58)];
            [buttons[x][y] setBackgroundImage:[UIImage imageNamed:@"gallery_back.png"] forState:UIControlStateNormal];
     //      [buttons[x][y] addTarget:self action:@selector(actionPick:) forControlEvents:UIControlEventTouchDown];
           [buttons[x][y] setTitleColor:[UIColor colorWithRed:0/255.0 green:0/255.0 blue:92/255.0 alpha:1] forState:UIControlStateNormal];
         //  buttons[x][y].titleLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:42];
            buttons[x][y].adjustsImageWhenHighlighted = NO;
            buttons[x][y].adjustsImageWhenDisabled = NO;
            buttons[x][y].tag = intTagNumber;
            [self.view addSubview:buttons[x][y]];

            intTagNumber++;
        }
       k++;

    }



}
- (IBAction)actionPick:(id)sender
{
    UIButton *button = (UIButton *)sender;
    NSLog(@"Button tag: %i",button.tag);
}

- (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [self updateUI];
    [self addBottomView];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(NSString *)getURL
{
    return [NSString stringWithFormat:@"%@%@studentprofileid=%@",ROOT_URL,ImageGallery_Data,[[[SharedPreferenceUtil getNSObject:STUDENT_DATA_JSON ]valueForKey:@"studentprofileid"] valueForKey:@"studentimagegallary"]];
}


-(void)updateUI
{
    [self addCutomTitleToNavigationController:@"Image Gallery"];
    [self addCustomBackButton];

    if (IS_IOS7)
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Gallery_navigation2.png"] forBarMetrics:UIBarMetricsDefault];
    else
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Gallery_navigation.png"] forBarMetrics:UIBarMetricsDefault];








  //  NSMutableArray *datainview =(NSMutableArray*) [SharedPreferenceUtil getNSObject:@"gallary_data"];
 //   NSString *groupname1=[datainview valueForKey:@"group_name"];
//    NSLog(@"The group is : %@",groupname1);
//    NSLog(@"The data in  View is : %@",datainview);
//    [march2015label setText:groupname1];



}




@end
//DPSGalleryViewController.m
//DPSApp
//
//由EDUNEXT于2015年5月18日创建。
//版权所有(c)2015 Edunext。版权所有。
//
#导入“DPSGalleryViewController.h”
#导入“dpsapparser.h”
#导入“dpsapservice.h”
#导入“SharedReferenceUtil.h”
#导入“DPSGallery1ViewController.h”
#导入“UIImageView+WebCache.h”
@接口DPSGalleryViewController()
{
NSMutableArray*imagearray;
UIImageView*groupimageView;
//NSMutableArray*数组;
//UIButton*按钮;
NSString*文件路径1;
}
@结束
@DPSGalleryViewController的实现
@合成sv;
-(iAction)第一视图:(id)发送方
{
UIButton*aButton=[[UIButton alloc]init];//[[UIButton Button类型:UIButtonTypeCustom]initWithFrame:CGRectMake(120,60,80,60)];
aButton.backgroundColor=[UIColor clearColor];
[self.view addSubview:aButton];
DPSGallery1ViewController*galleryViewController=[self.storyboard实例化eviewcontrollerwhiteIdentifier:@“gallery1view”];
[self.navigationController pushViewController:galleryViewController动画:是];
}
-(无效)viewDidLoad
{
//定格
sv.frame=CGRectMake(0,0,320,480);
//设置内容大小
[sv setContentSize:CGSizeMake(3201000)];
[超级视图下载];
//加载视图后执行任何其他设置。
NSInteger intTagNumber=0;
NSInteger intLeftMargin=10;//与屏幕边缘的水平偏移
NSInteger intTopMargin=20;//屏幕边缘的垂直偏移
NSInteger intXSpacing=85;//按钮原点之间的像素数(水平)
NSInteger intyspace=79;//按钮原点之间的像素数(垂直)
NSInteger intXTile;
NSInteger-intYTile;
int k=1;

对于(int y=1;y最好使用带有n个数字行的UITableView,为每个单元格创建一个按钮循环,并将其添加为单元格的contentview(作为列)。请按以下方式设置按钮的标记-

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;

    }


    for (int columnIndex = 0; columnIndex <4; columnIndex++)
    {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button addTarget:self
                   action:@selector(aMethod:)
         forControlEvents:UIControlEventTouchUpInside];
        button.tag = indexPath.row + columnIndex;
        [button setTitle:@"Show View" forState:UIControlStateNormal];
        button.frame = CGRectMake(0.0,columnIndex * 40.0 + 10.0, 40.0, 40.0);
        [cell. contentView addSubview:button];

    }


    return cell;

}

按钮在一个矩阵中是这样的,我想根据web服务动态创建。但是我们可以使用矩阵形式的循环。是的,您可以动态更改行和列的编号,并调用[tableview reloaddata];
-(void)aMethod:(UIButton *)sender
    {

        int tagValue = sender.tag;

        int columnIndex = tagValue%4 ;
        int rowIndex = (tagValue - columnIndex)/4;

        NSLog(@"Button clicked Row %d Column %d",rowIndex,columnIndex);
    }