5

Dizeye birden çok dizeyi nasıl ekleyebilirim? Bunu yapmanın en kolay yolu nedir? Ben bir dizeye şey eklemek her zaman kod yeni bir satır oluşturmak istemiyorsanız , ben böyle bir şey yapmak istiyorum:Dizgiye birden fazla dizgi ekleme

NSString *recipeTitle = [@"<h5>Recipe name: " stringByAppendingFormat:recipe.name, @"</h5>"]; 
    NSLog(@"%@", recipeTitle); 

    // This shows: <h5>Recipe name: myrecipe 
    // Where's the </h5> closing that header ? It will only show up with the next line of code 

    recipeTitle = [recipeTitle stringByAppendingFormat:@"</h5>"]; 

    //my problem is that will result in more than 1k lines of programming 

Ben ille yeni bir satır sona dosya eklemeyi eklemek zorunda mıyım ekli her zaman? Bunu yapmak için daha hızlı/daha üretken bir yolu var mı?

E-posta gövdesini masaüstümdeki tablo görünümünde oluşturmaya çalışıyorum ve bu çok büyük bir dizi programlama satırıyla sonuçlanacak. Bana herhangi bir ipucu veya herhangi bir şey daha iyi bir şey verebilecek herhangi bir kimse bana e-posta bedenimi tablo görünümü verilerimi içeren bir tabloya yerleştirebilir miyim?

Bunu daha verimli hale getirmek için herhangi bir yardım takdir edilmektedir. Teşekkürler ! Carlos Farini.

// üzerinde ben var biraz çalıştıktan sonra:

-(IBAction)sendmail{ 
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; 
[composer setMailComposeDelegate:self]; 
NSString *recipeTitle = @"<h5>Recipe name: "; 
recipeTitle = [recipeTitle stringByAppendingFormat:recipe.name]; 
recipeTitle = [recipeTitle stringByAppendingFormat:@"</h5>"]; 

NSString *ingredientAmount = @""; 
NSString *ingredientAisle = @""; 
NSString *ingredientTitle = @""; 

NSString *tableFirstLine = @"<table width='90%' border='1'><tr><td>Ingredient</td><td>Amount</td><td>Aisle</td></tr>"; 
NSString *increments = @""; 
int i=0; 

for (i=0; i < [ingredients count]; i++) { 
    Ingredient *ingredient = [ingredients objectAtIndex:i]; 
    ingredientTitle = ingredient.name; 
    ingredientAmount = ingredient.amount; 
    ingredientAisle = ingredient.aisle; 

    increments = [increments stringByAppendingFormat:recipeTitle]; 
    increments = [tableFirstLine stringByAppendingFormat:@"<tr><td>"]; 
    increments = [increments stringByAppendingFormat:ingredientTitle]; 
    increments = [increments stringByAppendingFormat:@"</td><td>"]; 
    increments = [increments stringByAppendingFormat:ingredientAmount]; 
    increments = [increments stringByAppendingFormat:@"</td><td>"]; 
    increments = [increments stringByAppendingFormat:ingredientAisle]; 
    increments = [increments stringByAppendingFormat:@"</td></tr>"]; 
    if (i == ([ingredients count]-1)) { 
     //IF THIS IS THE LAST INGREDIENT, CLOSE THE TABLE 
     increments = [increments stringByAppendingFormat:@"</table>"]; 
    } 
} 

NSLog(@"CODE:: %@", increments); 

if ([MFMailComposeViewController canSendMail]) { 
    [composer setToRecipients:[NSArray arrayWithObjects:@"[email protected]", nil]]; 
    [composer setSubject:@"subject here"]; 
    [composer setMessageBody:increments isHTML:YES]; 
    [composer setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [self presentModalViewController:composer animated:YES]; 
    [composer release]; 
}else { 
    [composer release]; 
} 

}

Ama sonra tekrar, bu tabloda sadece bir satır gösteriyor. Burada neyi yanlış yapıyorum?

cevap

5

Nasıl böyle bir şey hakkında:

NSString *recipeTitle = [NSString stringWithFormat:@"<h5>Recipe name: %@ </h5>", recipe.name]; 
+0

Birden% @ koymak ve sonra ... gibi gidebilir, recipe.name, recipe.preptime, recipe.included? Aynı kodda üç dizgi ekleyecektim. Bu kötü olmaz ... – Farini

+1

Evet, yapabilirsin. Ayrıca, dizeleri oluşturmanın daha fazla yolu için belgeleri kontrol edebilirsiniz. – Odrakir

+0

Bu mükemmel. Aydınlanma için teşekkürler – Farini

İlgili konular