Object_C 宏的定义格式

本文介绍如何在iOS开发中使用UIAlertView宏定义,并提供一个具体示例来展示其使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UIAlertView 宏定义:
#defineALERT_MSG(title,msg)\
{\
UIAlertView*_alert=[[UIAlertView alloc] initWithTitle:title message:msgdelegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];\
_alert.transform=CGAffineTransformMakeTranslation(0,80); \
[_alert show];\
[_alert release];\

}

通过下面利用,第一个是标题,第二个是提示
ALERT_MSG(@"提示",@"您现在未设置服务器IP");


``` #include <stdio.h> #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> #include <stdlib.h> #include <json/json.h> #include <pthread.h> #include <string.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include "video.h" #include "motor.h" int main() { int sockfd = socket(AF_INET, SOCK_STREAM, 0); if (-1 == sockfd) { perror("socket"); exit(1); } struct sockaddr_in ali_addr; memset(&ali_addr, 0, sizeof(ali_addr)); ali_addr.sin_family = AF_INET; ali_addr.sin_port = htons(ALI_PORT); ali_addr.sin_addr.s_addr = inet_addr(ALI_ADDR); //connect ali server if (connect(sockfd, (struct sockaddr *)&ali_addr, sizeof(ali_addr)) < 0) { perror("connect ali server failure"); exit(1); } //create json object struct json_object *obj = (struct json_object *)json_object_new_object(); json_object_object_add(obj, "cmd", json_object_new_string("info")); json_object_object_add(obj, "deviceid", json_object_new_string("0001")); const char *s = (const char *)json_object_to_json_string(obj); if (send(sockfd, s, strlen(s), 0) < 0) { perror("send to ali failure"); exit(1); } //recv server port info char buf[256] = {0}; if (recv(sockfd, buf, sizeof(buf), 0) < 0) { perror("recv from server failure"); exit(1); } struct json_object *json = json_tokener_parse(buf); struct json_object *cmd, *port; int server_udp_port; cmd = json_object_object_get(json, "cmd"); port = json_object_object_get(json, "port"); if (!strcmp((const char *)json_object_get_string(cmd), "port_info")) { server_udp_port = json_object_get_int(port); } else { printf("recv from server error\n"); } //start new thread, send video data to ali server pthread_t tid; pthread_create(&tid, NULL, send_video_data, &server_udp_port); while (1) { memset(buf, 0, sizeof(buf)); if (recv(sockfd, buf, sizeof(buf), 0) < 0) { perror("recv failure"); } json = json_tokener_parse(buf); struct json_object *cmd, *action; cmd = json_object_object_get(json, "cmd"); action = json_object_object_get(json, "action"); if (!strcmp((const char *)json_object_get_string(cmd), "control")) { const char *act = json_object_get_string(action); if (!strcmp(act, "left")) //left { motor_turn_left(); } else if (!strcmp(act, "right")) { motor_turn_right(); } else if (!strcmp(act, "up")) { motor_turn_up(); } else if (!strcmp(act, "down")) { motor_turn_down(); } } } return 0; }```注释代码
最新发布
04-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值