发送邮件tableviewnsarray



这是我的NSObject代码;

Task.h

#import <Foundation/Foundation.h>
@interface Task : NSObject
@property (nonatomic,strong) NSString *name;
@property (nonatomic,assign) BOOL done;
-(id)initWithName:(NSString *)name done:(BOOL)done;
@end

Task.m

#import "Task.h"
@implementation Task
@synthesize name = _name;
@synthesize done = _done;
-(id)initWithName:(NSString *)name done:(BOOL)done {
    self = [super init];
    if (self) {
        self.name = name;
        self.done = done;
    }
    return self;
}

这是我的邮件发送代码

Task *task = [[Task alloc]init];
        MFMailComposeViewController *sendmail = [[MFMailComposeViewController alloc]init];
        [sendmail setMailComposeDelegate:self];
        NSString *message = [_tasks addObject:task]; // Error is here.
        [sendmail setMessageBody:message isHTML:NO];
        [sendmail setSubject:@"Test"];
        [self presentViewController:sendmail animated:YES completion:nil];
我不知道该怎么做。我只是想把名单邮寄出去。我错在哪里?我怎样才能解决这个问题呢?

Tasklistviewcontroller.m

@synthesize tasks = _tasks;

我正在从任务表视图转移。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *NotDoneCellIdentifier = @"NotDoneTaskCell";
    static NSString *DoneCellIdentifier = @"DoneTaskCell";
    Task *currentTask = [self.tasks objectAtIndex:indexPath.row];
    NSString *cellIdentifier = currentTask.done ? DoneCellIdentifier : NotDoneCellIdentifier;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    // Configure the cell...
    cell.textLabel.text = currentTask.name;
    return cell;
}

我不知道你的代码到底出了什么问题,因为你没有提供错误,而且我对Objective-C还不是那么精通。

我怀疑这是因为你引用了"_tasks",我没有看到创建该类的其他代码。

NSString *message = [_tasks addObject:task];

另一个问题是你使用task作为数组的输入对象,但它可能不包含任何东西。

你可能不想这样:

 Task *task = [[Task alloc] initWithName:@"Task 1"];
 NSString *message = [[NSString alloc] initWithFormat:@"Task name is %@", task.name];

我猜你还没有发布完整的代码。

你还忘了在头文件中包含正确的应用内邮件框架:

#import <MessageUI/MFMailComposeViewController.h>

不要忘记将框架也添加到您的项目中!

顺便说一下,你可以用synthesize删除这两行,现在编译器会自动这样做。很漂亮,不是吗?

最新更新