sách gpt4 ai đã đi

NSMutable NSArray - Làm thế nào để tránh tất cả những dòng này và sử dụng mảng chiều hoặc mảng 3D?

In lại 作者:行者123 更新时间:2023-12-03 17:08:44 hai mươi bốn 4
mua khóa gpt4 Nike

enter code here- (void)viewDidLoad {

NSMutableArray *imageViewArray= [[NSMutableArray alloc] init];
for ( int i = 1; i < 10 ; i++ ) {

NSString *imgName = [NSString stringWithFormat:@"pic%i.jpg", i];
UIImage *img = [UIImage imageNamed:imgName];
[imageViewArray addObject:img];
}
self.gallery = imageViewArray;
[imageViewArray release];


NSString *p1 = [NSString stringWithFormat:@"p1.jpg"];
NSString *p2 = [NSString stringWithFormat:@"p2.jpg"];
NSString *p3 = [NSString stringWithFormat:@"p3.jpg"];
NSString *p4 = [NSString stringWithFormat:@"p4.jpg"];
NSString *p5 = [NSString stringWithFormat:@"p5.jpg"];
NSString *p6 = [NSString stringWithFormat:@"p6.jpg"];
NSString *p7 = [NSString stringWithFormat:@"p7.jpg"];
NSString *p8 = [NSString stringWithFormat:@"p8.jpg"];
NSString *p9 = [NSString stringWithFormat:@"p9.jpg"];
UIImage *P1V = [UIImage imageNamed:p1];
UIImage *P2V = [UIImage imageNamed:p2];
UIImage *P3V = [UIImage imageNamed:p3];
UIImage *P4V = [UIImage imageNamed:p4];
UIImage *P5V = [UIImage imageNamed:p5];
UIImage *P6V = [UIImage imageNamed:p6];
UIImage *P7V = [UIImage imageNamed:p7];
UIImage *P8V = [UIImage imageNamed:p8];
UIImage *P9V = [UIImage imageNamed:p9];
NSArray *imageViewArray2 = [[NSArray alloc] initWithObjects:P1V,P2V,P3V,P4V,P5V,P6V,P7V,P8V,P9V,nil];
self.gallery2 = imageViewArray2;
[imageViewArray2 release];

NSArray *array = [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",nil];
self.list = array;
[array release];

[super viewDidLoad];

}

1 Câu trả lời

您应该做的是将文件名放入数组中,然后简单地在循环内替换该变量。

下面是一些代码来证明这一点:

NSArray *dayStrings = [NSArray arrayWithObjects: @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", nil];
NSArray *timeStrings = [NSArray arrayWithObjects: @"9 AM", @"10 AM", @"11 AM", @"12 PM", @"1 PM", @"2 PM", @"3 PM", @"4 PM", @"5 PM", nil];

int i;
NSMutableAttributedString *day, *time;

for(i = 0; i < HORIZONTAL_CELL_COUNT; i++)
{
day = [[[NSMutableAttributedString alloc] initWithString:[dayStrings objectAtIndex:i] attributes:attributes] autorelease];
[days addObject:day];
}

for(i = 0; i < VERTICAL_CELL_COUNT; i++)
{
time = [[[NSMutableAttributedString alloc] initWithString:[timeStrings objectAtIndex:i] attributes:attributes] autorelease];
[times addObject:time];
}

关于cocoa - NSMutable NSArray 数组 - 如何避免所有这些行并使用维度或 3D 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/574448/

hai mươi bốn 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com