将C Type Array从NSObject传递给视图控制器

时间:2013-04-30 22:20:26

标签: uiviewcontroller nsobject

我在NSObject中定义了一个C类型数组,我已经设置了Setters&干将 我已经用UIView drawrect {}方法填充了数组

    - (void)drawRect:(CGRect)rect
{

    // Drawing code
    int n = 8;         // row and column count
    int padding = n*2;    // distance beetween dots
    //float radius=4;
    float radius = MIN((rect.size.width-(n+1)*padding)/(n*6), (rect.size.height-(n+1)*padding)/(n*6)); // radius depending on rect size


    Board *board=[[Board alloc]init];


    for (int y = 0; y<n; y++) {
        for (int x = 0; x<n-1; x++) {

            CGRect linehor=CGRectMake(1.5*padding+2*radius+(padding+radius*6)*x, padding+.5*radius+(padding+radius*6)*y, 2*padding, 2*radius);
            Lines *line=[[Lines alloc]initWithFrame:linehor];
            line.IDlabel.text=[NSString stringWithFormat:@"%d,%d",x,y];
            [board  setthelinestateatcol:x androw:y withstate:YES];//The Setters Part 
            line.col=x;
            line.row=y;
            [self addSubview:line];
        }
    }
    for (int y = 0; y<n-1; y++) {
        for (int x = 0; x<n; x++) {
                CGRect linehor=CGRectMake(1*padding+2*radius+(padding+radius*6)*x, 1.25*padding+.5*radius+(padding+radius*6)*y, 2*radius, 2*padding);
            vertLines *line=[[vertLines alloc]initWithFrame:linehor];
            line.IDlabel.text=[NSString stringWithFormat:@"%d,%d",x,y];
            [board  setthevertlinestateatcol:x androw:y withstate:YES];
            line.col=x;
            line.row=y;

            [self addSubview:line];
        }
    }
NSLog(@"Testing the array%d",[board checklinestateatcol:2 androw:3]);
}

说到Getters,它不起作用,C数组的行为从未被填充,它全部为0 这是h文件中的viewcontroller代码:

    @interface ViewController : UIViewController{


    Board *board1;

}
m文件中的

-(void)checkthetoucheffect:(NSNotification*)notification{

int x=[[[notification userInfo]objectForKey:@"x"]integerValue];
int y=[[[notification userInfo]objectForKey:@"y"]integerValue];

BOOL hhh= [board1 checklinestateatcol:x androw:y];
BOOL fff= [board1 checklinestateatcol:x-1 androw:y-1];
NSLog(@"this should right this time %d ,%d",hhh,fff);
}

NS对象中C类型数组的定义如下

    @implementation Board
{

    BOOL horlinearray2[8][8];
    BOOL vertlinearray2[8][8];
}
-(BOOL)checklinestateatcol:(NSInteger)xcol androw:(NSInteger)yrow {

    return horlinearray2[xcol][yrow];
}
-(void)setthelinestateatcol:(NSInteger)xcol androw:(NSInteger)yrow withstate:(BOOL)state{
    horlinearray2[xcol][yrow]=state;

}

我知道NSObject&amp;和NSObject之间的这个基本共享对象uiviewcontroller,但我不知道解决它的最佳方法是什么? 我应该使用单身还是其他东西

0 个答案:

没有答案